High level question, with a "belongs-to" relationship .... you
usually put the primary key of the parent object into the table of the
child. I would like to know if there is a way to reference the parent
object, via something else than the primary key. Here is a simple
example:
model:
Class Property "belongs-to" class Neighborhood
Class Neighborhood "has-many" class Properties
SQL DB:
Properties Table contains a field called AREA.
Neighborhood Table contains a field called AREA_ID
Property.AREA == Neighborhood.AREA_ID // these two data points match
Can I reference the Neighborhood Object from the Property Object,
without adding the primary key from the Neighborhood table to the
property table? Ideally, I would like to write code like: <%
property.neighborhood.name %>, as I would be able to if I added the
primary Neighborhood id key to the Property table.
Is Neighborhood.area unique for a given neighborhood, i.e. not two
neighborhoods have the same area.
If so then it sounds like area should be the primary key for
neighborhoods. If you have to name it area then you need to do
something like (this is off the top of my head and untested):
1) Make it the actual primary key, if you are using migrations use the
;id => false option on create table something like: