Having these models: class League < Tournament has_many :league_positions, :order => :position, :dependent => :destroy end class LeaguePosition < ActiveRecord::Base belongs_to :league, :class_name => ''League'', :foreign_key => ''tournament_id'' acts_as_list :scope => :tournament_id end when I try to destroy a League (so its LeaguePositions too) I get these SQL error: Unknown column ''league_positions.league_id'' in ''where clause'': SELECT * FROM league_positions WHERE (league_positions.league_id = 1) ORDER BY position I thought declaring :foreign_key => ''tournament_id'' was enough to let league_positions knows who is its owner. What am I doing wrong? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> Having these models: > > class League < Tournament > has_many :league_positions, :order => :position, :dependent => > :destroy > end > > class LeaguePosition < ActiveRecord::Base > belongs_to :league, :class_name => ''League'', :foreign_key => > ''tournament_id'' > acts_as_list :scope => :tournament_id > end > > when I try to destroy a League (so its LeaguePositions too) I get these > SQL error: > > Unknown column ''league_positions.league_id'' in ''where clause'': SELECT * > FROM league_positions WHERE (league_positions.league_id = 1) ORDER BY > positionDoes your League table have a field league_positions_id? Does your LeaguePositions table have a field tournament_id? -Ben Lisbakken --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Excuse me I was a little off. Your League table doesn''t need to have a league_positions_id. The problem is that LeaguePositions knows that it is connected to Leagues by tournament_id. But Leagues think that the key that connects a LeaguePositions to it is called league_positions_id. this can be fixed in two ways #1 class League < Tournament has_many :league_positions, :order => :position, :dependent => :destroy, :class => ''LeaguePositions'', :foreign_key => ''tournament_id'' end OR #2 change the foreign key in LeaguePositions from being tournament_id to being league_id. Then change that line in the LeaguePositions class. -Ben Lisbakken --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> #1 > class League < Tournament > has_many :league_positions, :order => :position, :dependent => > :destroy, :class => ''LeaguePositions'', :foreign_key => ''tournament_id'' > endI''ve chosen the 2nd option, it works, but I had thought that declaring the :foreign_key and :class_name at belongs_to relationship in LeaguePosition model was enough to tell the framework how the relationship is. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---