How change :foreign_key on :through

Hi Guys.
(I’m Asian. so my eng is very poor. sorry!)

i want to change :foreign_key on has_many :through
code is

has_many :following_members, :class_name => “Follow”, :dependent
=> :destroy
has_many :followings, :foreign_key => “target_id”, :through
=> :following_members, :source => :user

but return is don’t used foreign_key(target_id)

i think… solution is

  1. use “find_sql”
  2. def followings
    but i don’t like these.

It’s going to be hard to give advice without the source to the Follow
model - that will determine what you need to specify in
has_many :through.

–Matt J.

ohoo, really? ;(

i solved by “find_sql”
i don’t like it ;p

i finded solution!

#Follow Model
belongs_to :target, :foreign_key => ‘target_id’, :class_name => ‘User’

#User Model
has_many :followings, :foreign_key => “target_id”, :through
=> :following_members, :source => :target

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs