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 methoduser_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

[email protected] 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.