Question

If I have to save an object to the database which has a relationships, do I have that dao do all the saving itself, or to delegate to other DAO's. If it should delegate to other DAOs, should that be done in the DAO itself, or in a layer above (like a service layer)? I would use an ORM for this, except that in PHP, nothing good exists yet.

Was it helpful?

Solution

I think the answer depends on ownership.

If the Parent owns the Children, and there's no possibility of creating a Child without a Parent, then it should be just ParentDao and no ChildDao at all.

If you can create a Child without a Parent, you'll need a ChildDao for its CRUD operations. In that case, you could have the ParentDao own a reference to a ChildDao and defer Child CRUD operations to it.

OTHER TIPS

I agree with duffymo's answer - but am interested as to your statement

I would use an ORM for this, except that in PHP, nothing good exists yet

I've used both Doctrine and Propel and have found them both to be very capable. My personal preference is Doctrine although a significant amount of improvements have been made in Propel 1.3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top