Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Add :from to has_many, belongs_to, etc

#2147

Currently, we have the need for the following in our app:

class Game < ActiveRecord::Base
  has_many :summarized_game_players, :from => 'v_game_player_statuses',
           :class_name => 'GamePlayer', :readonly => true
end

This is to create an association that loads a GamePlayer object, but gets the data from v_game_player_statuses.

The workaround we have is this:

class Game < ActiveRecord::Base
  has_many :summarized_game_players, :finder_sql => 'SELECT * FROM v_game_player_statuses where game_id = #{id}',
         :class_name => 'GamePlayer', :readonly => true
end

Which works, but having :from support to be consistent with find() would be really nice.

I will gladly attempt a patch and required tests, but I'm just trying to sift through active_record/associations and I'm a bit lost where to add it. Suggestions or thoughts?

Thanks, Nate

Reported by Nate Wiger · March 6th, 2009 @ 02:25 AM

State: invalid
Milestone: 2.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: none

Activity

  1. Steve St. Martin
    Steve St. Martin
    • Tag changed from activerecord, active_record, associations, belongs_to, edge, feature, has_many, rails to activerecord, active_record, associations, belongs_to, edge, feature, has_many, invalid, rails
    • Assigned user set to Ryan Bigg

    What your looking for is likely has_many :through http://guides.rubyonrails.org/association_basics.html#the-has-many-....

    can be marked as invalid

    April 15th, 2010 @ 09:05 PM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to invalid

    April 15th, 2010 @ 10:44 PM