Why through and foreign_key not working?

I need SQL :

SELECT `activities`.* FROM `activities` INNER JOIN `friendships` ON `activities`.user_id = `friendships`.friend_id WHERE `friendships`.user_id = 1

My User Model code:

has_many :friendships, :dependent => :destroy has_many :friends, :through => :friendships has_many :activities

I need SQL :

SELECT `activities`.* FROM `activities` INNER JOIN `friendships` ON `activities`.user_id = `friendships`.friend_id WHERE `friendships`.user_id = 1

My User Model code:

has_many :friendships, :dependent => :destroy has_many :friends, :through => :friendships has_many :activities ############################## has_many :friends_activities, :foreign_key => :user_id, :class_name => 'Activity', :through => :friendships, :source => :friend

Rails3 return:

ON `activities`.id = `friendships`.friend_id ??! :foreign_key is ignored

Why ?!!!!

With has many through you use the :source option to tell it which of the associations of friendships to follow to get to the desired row(s)

Fred

Frederick Cheung wrote:

With has many through you use the :source option to tell it which of the associations of friendships to follow to get to the desired row(s)

Fred

Now~ I need `activities`.user_id not is `activities`.id :smiley:

VTD-XML 2.9, the next generation XML Processing API for SOA and Cloud computing, has been released. Please visit https://sourceforge.net/projects/vtd-xml/files/ to download the latest version. a… Strict Conformance a… VTD-XML now fully conforms to XML namespace 1.0 spec b… Performance Improvement a… Significantly improved parsing performance for small XML files c… Expand Core VTD-XML API a… Adds getPrefixString(), and toNormalizedString2() d… Cutting/Splitting a… Adds getSiblingElementFragment() e… A number of bug fixes and code enhancement including: a… Fixes a bug for reading very large XML documents on some platforms b… Fixes a bug in parsing processing instruction c… Fixes a bug in outputAndReparse()

Jimmy Zhang wrote:

VTD-XML 2.9, the next generation XML Processing API for SOA and Cloud computing, has been released.

[...]

Please don't hijack threads. And this is off topic anyway.

Best,

Frederick Cheung wrote: > With has many through you use the :source option to tell it which of > the associations of friendships to follow to get to the desired row(s)

> Fred

Now~ I need `activities`.user_id not is `activities`.id :smiley:

Then you need to change the source association to point at what you want (i think belongs_to has a primary_key option these days)

Fred