ruby on rails - Nested Has Many Through Plugin and Named Scopes -
I have a user model (: name, password, email:), and event model (: name,: etc.) and Interest Model (: Name) [> All Singles & lt;]
Then I created two joining tables -> User lists and events; Each has no primary key and only includes user_id / interest_id and event_id / interest_id. [> Plural & lt;]
use my model
user.rb = & gt; Has_many: users_interests has_many: interests, via = & gt; : Users_interests has_many: events_interests, via = & gt; : Interests have_many: events ,: through = & gt; : Events_interests event.rb = & gt; Has_many: events_interests are_ many: interests, via = & gt; : Events_interests has_many: users_interests ,: through = & gt; : Interests have_many: users ,: through = & gt; : Users_interests interest.rb = & gt; Has_and_belongs_to_many: User has_and_belongs_to_many: events events_interests.rb = & gt; Belongs_to: Interests related: Events users_interests.rb = & gt; Related: For user related: Interests
Whew..ok So I wanted to create a named_scope which looks for all the events that share interest with all special events. Here's some code that has helped me.
named_scope: shares_interest_with_users, lambda {| User | {: Johns = & gt; : Users_interests ,: conditions = & gt; {: Users_interests = & gt; {: User_id = & gt; User}}}}
When I run the controller =>
@user = User.find (1) @events = Event.shares_interest_with_user ( @user)
I get an error:
uninitialized continuous event: EventsInterest
Do anybody see Could I mess up?
You may have given some wrong name on the way. At a glance, I would say that you do not have a file or class wrong. Remember the model name Important will always be singular in file and class names, or will not make railway connections. Another source of your problem is that for practice related logic, practice should also be singular. Even if you had anything right, then with the interests of the users, HABTM relations would have put an error while running the scope of your name.
I was able to solve your error with the following error.
user.rb
Class User & lt; ActiveRecord :: Base has has_many: users_interests has_many: Interests, via = & gt; : Users_interests has_many: events_interests, via = & gt; : Interests have_many: events ,: through = & gt; : Events_interests end
users_interest.rb
Classes UsersInterest & lt; ActiveRecord :: Base is_to: related to user: interest end
interest.rb
class interest < ActiveRecord :: Base has_many: users ,: through = & gt; : Users_interests has_many: users_interests has_many: events_interests has_many: events, via = & gt; : Event_interests end
** events_interest.rb
Class Events & lt; ActiveCord :: Base is_to: Interests: To: Event Ended
event.rb
Comments
Post a Comment