# Is there a bug with habtm and the "\_ids" method?

**URL:** <https://www.ruby-forum.com/t/is-there-a-bug-with-habtm-and-the-ids-method/72089>\
**Category:** Rails\
**Created:** [October 14, 2006, 1:52am UTC](https://www.ruby-forum.com/t/is-there-a-bug-with-habtm-and-the-ids-method/72089 "2006-10-14T01:52:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 14, 2006, 1:52am UTC](https://www.ruby-forum.com/t/is-there-a-bug-with-habtm-and-the-ids-method/72089/1 "2006-10-14T01:52:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 17, 2006, 3:23pm UTC](https://www.ruby-forum.com/t/is-there-a-bug-with-habtm-and-the-ids-method/72089/2 "2006-10-17T15:23:20Z")

</div>

removed\_email\_address@domain.invalid 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.
