Disclaimer: I'm not trying to provoke anyone here, I just want to offer some food for thought based upon past experience.
I haven't used Reactor yet. I've chosen to work with/on Reactor because I like the Active Record design pattern.
I've started going through the documentation, and found something I really don't like about hasOne. The foreign key is actually stored in the parent table.
http://livedocs.reactorframework.com/hasOne_tag.htmhttp://livedocs.reactorframework.com/hasMany.htm
The hasMany documentation goes on to say "There are two ways that hasMany relationships can be configured. The
first is just like
hasOne relationships except
in the opposite direction. Rather
than the parent object having a foreign key to the child object, the child
object has the foreign key to the parent."
Let's forget about Reactor for a moment. Let's forget about ColdFusion. Let's think only about database design.
A foreign key should only be added to a table if the record "belongs" to a record in another table. Again, a foreign key should only be added to a table if the record "belongs" to a record in another table.
The biggest argument for this is cascading deletes.
EXAMPLE (the proper way)
Employees
Addresses
- id
- street
- city
-
state
- zip
- employeeID
For this instance, let's just say that an employee has one address. The address clearly belongs to the employee. I can add a cascading delete (in the database) to the relationship, when an employee is deleted, then the address that belongs to that employee is also deleted. If I like, I can delete an address without affecting the employee record. The cascading delete prevents orphaned addresses. (granted, I'm going to also assume cascading deletes are built into reactor)
EXAMPLE (the way proposed in the docs)
Employees
- id
- firstName
- lastName
- addressID
Addresses
I can add a relationship here in the database, just like I did before. If I were to add a cascading delete (in the database), I have three problems: 1) if I delete an employee record, I now have an orphaned address record, 2) if I delete and address record, the employee record will also be deleted, and 3) you can create orphan address records - create an address record without having an employee record present.
This asserts my belief that good database design dictates that the foreign key should reside on the child record.
Back to Reactor.
My biggest beef with hasOne (other than what is already stated) is the statement in the hasMany doc: (paraphrased) "hasMany is just like hasOne, but in the opposite direction."
What the documentation should say is: "hasMany is just like hasOne, but it doesn't limit you to just one record." You might see where I'm going with this.
Let's say we build an application where there requirement changes, and multiple addresses need to be stored for each employee. We no longer have to reengineer our database, we can simply change our hasOne reference in the reactor config file to hasMany. This has nothing to do with how our application handles our relationships, but more to do with how we architected our database.
I think we really don't even need to do anything to reactor, but really just chagne the documentation to address conventions. Couldn't I then declare my hasOne relationship as such?
<object name="Employee">
<hasOne name="Address">
<relate from="id (parent PK)" to="employeeID (child FK)" />
</hasOne>
</object>
After writing and thinking about his a little more, my beef isn't really how Reactor handles hasOne, but really how the documentation tells someone how they should design their databases.
From my understanding, Reactor should still work the same with the way I declared my relationship above.
personally, I'd like to see something like the following, but this is just me:
<object name="Employee" primaryKey="id">
<hasOne name="Address" foreignKey="employeeID" />
</object>
Discuss!
-Dutch