Friday, 15 February 2013

ruby - Lazy loading: How do I do Model.include(:name) when foreign key has a different name than the model? -



ruby - Lazy loading: How do I do Model.include(:name) when foreign key has a different name than the model? -

i want lazy load user target objects in active record this:

target.include(:user)

but problem user_id foreign key named 'targeted_user_id', not 'user_id'. how can accomplish this?

class target < activerecord::base belongs_to :user, foreign_key: 'targeted_user_id' end target.includes(:user)

good explanation here

ruby ruby-on-rails-3

No comments:

Post a Comment