Victor Lin
2011-Dec-24 05:00 UTC
3.2rc1 through association with dynamic conditions broken when using joins/includes
My app has feeds and items. Users can subscribe to feeds, which I track in a Subscription class. I wanted an association for all of a user''s unread items: class Subscription < ActiveRecord::Base belongs_to :feed belongs_to :user has_many :unread_items, :through => :feed, :source => :items, :conditions => proc { "not exists ( select * from readings where readings.item_id = items.id AND readings.user_id = #{user_id} )" } ... This works fine if I reference it directly (i.e, @user.subscriptions.first.unread_items). But if I try to eager load or join against it: eager load: ''self'' in the conditions proc refers to the intermediate object (here, the Feed class) which I don''t think is expected. Crashes because Feed obviously has no user_id in my app. join: ''self'' in the conditions proc refers to a JoinDependency object, which seems totally wrong. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/66WrX-IovzMJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Victor Lin
2011-Dec-24 05:01 UTC
Re: 3.2rc1 through association with dynamic conditions broken when using joins/includes
Er, to clarify, the error I''m getting is that the interpolation of #{user_id} in the association condition is undefined. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/M4hOkq0GRckJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.