views:

37

answers:

0

Hi, all

I need find friends activities:

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

My add this code to User Model:

has_many :friends_activities, 
         :class_name => 'Activity', 
         :through => :friendships, 
         :foreign_key => :user_id, 
         :source => :friend

But Rails return is:

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

I need :

`activities`.user_id = `friendships`.friend_id

But Now:

`activities`.id = `friendships`.friend_id

PS: My Tables:

create_table "activities", :force => true do |t|
     t.integer  "user_id"
     t.integer  "target_id"
     t.string   "target_type"
     t.string   "verb"
     t.datetime "created_at"
     t.datetime "updated_at"
end

create_table "friendships", :force => true do |t|
     t.integer  "user_id",    :null => false
     t.integer  "friend_id",  :null => false
     t.string   "state"
     t.datetime "created_at"
     t.datetime "updated_at"
end