I have a MS SQL database that I am accessing through ODBC. The tables do not conform to Rails defaults so I am having to re-assign the primary keys and foreign keys. I have the following: class DimPlayer < ActiveRecord::Base
set_primary_key "player_id" has_many :map_players end class MapPlayer < ActiveRecord::Base set_primary_key "map_id" belongs_to :dim_player, :foreign_key => "to_player_id" end When I do a search on MapPlayer, I can use the association with no problem, e.g. player_entries = MapPlayer.find(:all, :conditions => ["to_player_id = ?", player_id]) returns an array and elements of the array link back to the DimPlayer table as expected. (player_entries [0].dim_player) When I try it the other way, dim_player_found = DimPlayer.find(:first, :conditions => [ "surname = ?", "XXXX"]) dim_player_found.map_players gives me an error, such as the one below, which suggests I'm doing something wrong with the :foreign_key => "to_player_id" line. The error is S0022 (207) [unixODBC][FreeTDS][SQL Server]Invalid column name 'dim_player_id' which is what I would expect if I had not tried the foreign_key re-assignment. I can't see the wood for the trees - any help most appreciated! regards Martin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---