This project is archived and is in readonly mode.

#2147 ✓invalid
Nate Wiger

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

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

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

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=""></a>

People watching this ticket