ユーザー モデル (:name, :password, :email)、イベント モデル (:name, :etc)、Interest モデル (:name) があります。
次に、UsersInterests と EventsInterests の 2 つの結合テーブルを作成しました。それぞれが主キーを含まず、それぞれ user_id/interest_id と event_id/interest_id のみで構成されています。
私はActiveRecordを使用して、EventsInterestsのinterest.id = UsersInterestsのinterest.idであるすべてのイベントのリストを照会しようとしています
Nested Loop Pluginで has_many と belongs_to の関係を使用しています
私のモデルはそうのように見えます=>
user.rb
has_many :users_interests
has_many :interests, :through => :users_interests
event.rb
has_many :events_interests
has_many :interests, :through => :events_interests
興味.rb
belongs_to :users , :through => :users_interests
belongs_to :events , :through => :events_interests
users_interests.rb
belongs_to :users
belongs_to :interests
events_interests.rb
belongs_to :interests
belongs_to :events
@user= User.find(1) の場合、ユーザーが関心を持つイベントをどのようにクエリしますか?
私はこれを思いついた => @events.find(:all, :conditions => EventsInterests.interest_id = UsersInterests.interest_id) ??
しかし、私はエラーが発生します
undefined method `interest_id' for UsersInterests(user_id: integer, interest_id: integer):Class
うーん..wtf? 助けてください....私はこれに4日間ほど取り組んでいます