ruby on rails - HABTM Relationship and Named Scopes -


I am working on this for a while and I do not know where the error is there.

I have a user model (: name, password, email), and event model (: name,: etc.) and interest model (: name) [> all singular & 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 and lieutenant;]

My model has HABTM relationships such as

  user.rb = & gt; Has_and_belongs_to_many: Interests event.rb = & gt; Has_and_belongs_to_many: Interest interest.rb = & gt; Has_and_belongs_to_many: User has_and_belongs_to_many: events events_interests.rb = & gt; Has_and_belongs_to_many: Interests have_and_belongs_to_many: events_worlds.rb = & gt; Has_and_belongs_to_many: The user has__and_bangs_to_many: 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_Space: shares_interest_with_user, lambda {| User | {: Johns = & gt; "LEFT JOIN events_interests ei ON ei.event_id = Event.id" + "LEFT zone users_interests ui ON ui.interest_id = ei.interest_id" ,: conditions = & gt; ["Ui.user_id =?", User]}}  

when I get the controller =>

  @user = User.find (1) @events = Event.shares_interest_with_user (@user)  

I get a SQL error: "There are no such columns: Event.id: SELECT" events ". * Join the left of" events "events_interests Ei ON Ee.event_id = ........... "

Now I am sure the event model has an ID and I think all the column names are correct..at any What is it?

I recommend that you go away from HABT and instead of is_I: through .

The difference written by the SO user is explained here.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -