dtrusty-U6r7FCv0h4VBDgjK7y7TUQ@public.gmane.org
2006-Oct-13 23:50 UTC
is there a bug with habtm and the "_ids" method?
Hi, Is there some problem with the habtm "_ids" function. See this example: class User < ActiveRecord::Base has_and_belongs_to_many :groups end class Group < ActiveRecord::Base has_and_belongs_to_many :users end g=Group.find(1) print "size=", g.users.size, "\n" a=g.user_ids Here is the output: Group Load (0.000789) SELECT * FROM groups WHERE (groups.id = 1) LIMIT 1 Group Columns (0.001408) SHOW FIELDS FROM groups Join Table Columns (0.000971) SHOW FIELDS FROM groups_users User Load (0.002074) SELECT * FROM users INNER JOIN groups_users ON users.id = groups_users.user_id WHERE (groups_users.group_id = 1 ) size=2 /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1792:in `method_missing'': undefined method `user_ids'' for #<Group:0xb7923e60> (NoMethodError) As you can see, there are records in the association, but the "_ids" function is missing? Any ideas? Thanks, David --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Oct-17 13:19 UTC
Re: is there a bug with habtm and the "_ids" method?
dtrusty-U6r7FCv0h4VBDgjK7y7TUQ@public.gmane.org wrote:> As you can see, there are records in the association, but the "_ids" > function is missing?Rails only defines setter method for <singular_class>_ids, not a getter method. You have to write you own getter. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---