I’m moving towards an ORM for my codeigniter application and have chosen datamapper. However, in the rules section, it states the following:
A joining table must exist between
each related normal tables, regardless
of the type of relationship.
I have dozens of tables that are in a one->many relationship. Does this mean that I have to create intermediate (joining) tables between each of them as if they were many-many?
No, actually, the model that has a
$has_onerelationship set will have a field ending in_id,which refers to the object with the$has_manyrelationship set.So, for example:
In this case, DataMapper made a table
recipeswith arecipe_source_idcolumn, and arecipe_sourcestable that required no extra fields.Now, for many-to-many relationships, a join table will be created, and it follows a strict convention.
The join table name will be the two plurals of the joined models, separated by an underscore, in alphabetical order.
So, using this model:
Now, I end up with a join table in my database called
products_recipes.This is how it is handled by the DMZ DataMapper library (http://www.overzealous.com/dmz/), which is supposed to be a drop-in replacement for the old stensi DataMapper library, so I’m going to assume the conventions are the same.
Even so, I highly recommend making the switch to DMZ.