ruby on rails - Use ActiveRecord to Find Result of 5 Nested Tables -
I have a user model (: name, password, email:), and event model (: name,: etc.) and Interest Model (: Name)
Then I added two tables -> User feedback and Events; Not every primary key is included and only include user_id / interest_id event_id / interest_id respectively
I'm trying to use ActiveRecord to query a list of all events where interest.id = interest of EventsInterests
look like my model =>
user.rb
pre> has_many: users_interests has_many: interests, via = & gt; : Users_interests
event.rb
has_many: events_interests has_many: interest, through = & gt; : Events_interests
interest.rb
related_to: users ,: through = & gt; : Users_interests belong_to: Events, via = & gt; : Events_interests
users_interests.rb
belongs_to: those are_to: interests
events_interests.rb
related_to: Interests related_images
If @username = user.fund (1), how do I query the event in which a user would be interested?
I came up with this => @ events. Address (: all :: circumstance => events.root.in_reference_user =).
undefined method `interest_id 'for user (user_id: integer, interest_id: integer): class
Umm..weight? People of any help .... I have been on this for 4 days
First of all Console and make sure all your relationships work:
User.first.events User.first.interests Events.first.users Interests.first.users Interests.first.events #. ..and therefore
Just to clarify, a user lists their interests, and you want to get the list of events that match those interests?
User.first Interest.collect {| Interest |
Especially not efficient, but effective and easy to understand.
You can use the User.first.interests_singular_ids
to get the ID and search for interest_id IN (...)
with that list Pass for; I'm not sure how fast it will be.
Comments
Post a Comment