This project is archived and is in readonly mode.
Add :from to has_many, belongs_to, etc
Reported by Nate Wiger | March 6th, 2009 @ 02:25 AM | in 2.x
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
Comments and changes to this ticket
-
Steve St. Martin April 15th, 2010 @ 09:05 PM
- 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
-
Ryan Bigg April 15th, 2010 @ 10:44 PM
- State changed from new to invalid
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>