1

Ruby onRails3.2.2とMySQLを使用しています。has_many :through ActiveRecord::Associations次のSLQクエリを生成するメソッド(an )があります。

SELECT DISTINCT `articles`.*
           FROM `articles`
     INNER JOIN `articles_comments_associations` `comment_associations_articles`
             ON `comment_associations_articles`.`article_id` = `articles`.`id`
     INNER JOIN `articles_comments_associations`
             ON `articles`.`id` = `articles_comments_associations`.`article_id`
          WHERE `articles_comments_associations`.`comment_id` = 223
            AND (articles_comments_associations.user_id IN (2))

それが何を意味するのかINNER JOIN 'articles_comments_associations' 'comment_associations_articles':には複数のデータベーステーブルステートメントがあります)、およびという名前のデータベーステーブルがないINNER JOINためにSQLクエリがどのように機能する可能性があるのか​​を理解したいと思います。エラーですか(期待どおりに機能する場合でも)comment_associations_articles

4

1 に答える 1

4

これはテーブルエイリアスです。articles_comments_associationsつまり、クエリでさらに参照するcomment_associations_articlesために、テーブルの名前をに変更しています。テーブル/フィールド参照の後に別の名前を付けるだけで、任意のフィールドまたはテーブルにエイリアスを設定できます。

于 2012-06-26T15:03:12.707 に答える