_ids - has_many polymorphic

When using has_many :through polymorphic relationships, the magic method "_ids" does not work correctly, as it doesn't include the source_type. Instead, you need to use the relationship names and .pluck(:id). This appears to be a known bug in Rails. There are several threads about conditions not being passed to the _ids method for has_many :through. I haven't tested it in Rails 3.1

Only the usergroup.rb and taxonomy.rb defines has_many :through polymorphic relationships using :source

> When using has_many :through polymorphic relationships, the magic method
> "_ids" does not work correctly, as it doesn't include the source_type.
> Instead, you need to use the relationship names and .pluck(:id). This
> appears to be a known bug in Rails. There are several threads about
> conditions not being passed to the _ids method for has_many :through. I
> haven't tested it in Rails 3.1
>
> Thanks!
maybe in this kind of cases its saver to use the join class directly, e.g.

TaxableTaxonomy.where(:taxable_type => 'Subnet', :taxonomy_id =>
'id-you-are-searching-for').pluck(:taxable_id)

Ohad

ยทยทยท On Sun, Dec 30, 2012 at 3:09 PM, Joseph Magen wrote:

Only the usergroup.rb and taxonomy.rb defines has_many :through
polymorphic relationships using :source