I am designing a database schema for my project, where I seem to have been stuck by a strange vision-block (in the sense that, I have never had this issue before since its virtually too easy to resolve, except in this particular case – for me)
I have an entity homes, that can have various facilities.
So, I have declared a model: FacilitySet that looks like:
id, home_id, parking, electricity
As you can see, each row of facility_sets table corresponds to a Home.
But, in my opinion, it would make a whole lot more sense to me, if I could say: a home has_many facilities, rather than a home has_one facility_set. This, also, provides an advantage that I can simply say: @home.facilities, rather than @home.facility_set
The real problem is that I can not understand how to structure the facilities table in the database, so that I can simply declare:
class Home << ActiveRecord::Base
has_many :facilities
..
end
and access facilities like: @home.facilities
I am, currently, doing:
class Home << ActiveRecord::Base
has_one :facility_set
..
end
and access facilities like: @home.facility_set, which really makes me feel I am doing something horribly wrong!! :~)
Its early morning here, and I would really really appreciate any ray-of-ho(m)e for me.
Regards
Now use the facilities name and values field to store things like parking, electricity, etc. You may want to create a FacilityType class that has_many Facilities, and keep parking, electricity, etc., in there.