On 26 May 2011 07:07, Aaron Mills <[email protected]> wrote: > I am still somewhat new to rails and I am not getting the results I am > expecting with my models.. perhapse I do not understand something, or > just didn't set something up right. > > I have three models: > > class Coordinator < ActiveRecord::Base > belongs_to :county > belongs_to :state > end > > class State < ActiveRecord::Base > has_many :counties > has_many :coordinators, :through => :counties > accepts_nested_attributes_for :counties, :coordinators > end > > class County < ActiveRecord::Base > belongs_to :state > has_one :coordinator > accepts_nested_attributes_for :coordinator > scope :returncounty, lambda {|state| where(:state_id => state)} > end
Probably not associated with your problem but there is something not right above, you have two routes to coordinator from state. You have coordinator belongs to state (implying coordinator has a state_id column) and so you should also have state has many coordinators (which you have not specified). You also have coordinator belongs to county and county has one coordinator, but then in state you also have state belongs_to county and state has_many coordinators through counties. So when you say @state.coordinators it will get the coordinators from the counties, in which case you should not have coordinator belongs to state. Colin -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

