This project is archived and is in readonly mode.

#6153 ✓resolved
Yuval Kordov

Accessing associations via x_ids no longer uses association conditions

Reported by Yuval Kordov | December 11th, 2010 @ 11:51 PM

I'm upgrading my Rails app from 2.3.5 to 3.0.3 and have found the following:

user.rb
has_many :relationships
has_many :contacts, :through => :relationships, :conditions => {:relationships => {:status => "1"}}

In Rails 2.3.5, I could call user.contact_ids and it would run through the entire condition:

user.contact_ids =>
SELECT users.id FROM users INNER JOIN relationships ON users.id = relationships.contact_id WHERE ((relationships.user_id = 2) AND ((relationships.status = 1)))

In Rails 3.0.3, it seems to be ignoring the parameters altogether.

user.contact_ids =>
SELECT DISTINCT relationships.contact_id FROM relationships WHERE (relationships.user_id = 2)

Hopefully I'm missing something obvious here, but this change has put a serious wrench in my code, where I was using _ids associations for efficiency when I only ever needed IDs.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages