I have a self referential association like this:
class Influencer < ActiveRecord::Base
has_many :followers, :class_name => 'Following', :foreign_key => 'influencer_id'
has_many :following, :class_name => 'Following', :foreign_key => 'follower_id'
on my influencer table I have a field called “external_identifier”
I want to check my followers for a given external_identifier, so normally I would do an :include so it does a join.
I tried:
myinfluencer.followers.find(:first, :include => 'influencers', :conditions => ["influencers.external_identifier = ?","934394343434"])
but it errors with “influencers” is not an association, I also tried “followers”, neither seem to work properly.
Try
:include => :follower.myinfluencer.followersreturns a has_many association, so when you are joining in order to test a condition on the related model (Influencer), you need to use thebelongs_toside of the association, which in this case isbelongs_to :follower.