Hi Folks,
I’m totally confused - I have 3 tables
search, pickup_search and dropoff_search
pickup_search and dropoff_search are nearly identical and each contain
the search_id key.
My Models are as follows.
class Search < ActiveRecord::Base
has_one :pickup_search
has_one :dropoff_search
end
class PickupSearch < ActiveRecord::Base
belongs_to :searches
end
class DropoffSearch < ActiveRecord::Base
belongs_to :searches
end
So what I want to do is create a new search, then a new pickup_search
and a new dropoff_search.
I tried in my controllers new method to do
def new
@search = Search.new
@search.pickup_search.new
@search.dropoff_search.new
end
however it throws the error when creating a new pickup and dropoff
search
NoMethodError (You have a nil object when you didn’t expect it!
However if I change the relationship in search to has_many it works!!!
However for any given ‘search’ there will only be one pickup_search and
dropoff_Search so it shouldn’t be a has_many relationship… or am I
modelling this incorrectly
(FYI the pickup_search and dropoff_date contains date/destination info)
Any help much appreciated!
Peter