Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I use Unit of work pattern to commit all new, dirty, deleted entities to the DB (using a db_mapper).

Example of entities are: Student and Class

So Student->registerDirty() will add this entity to the dirty pool that will be saved to the DB when commit() will be called.

My problem is that Student can also hold collection of classes (Student->getClasses) and I am not sure how to integrate this into the unit of work pattern so it will only commit the new, updated or deleted.

Can any one recommend me how to integrate this?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Simple : the collection of Classes will record what was added or removed and will commit those items accordingly.

share|improve this answer
    
So you suggest tracking changes inside the collection class? and then add the whole collection to the UoW. Then commit() will also loop on all 'dirty' collections? –  michaelbn Oct 20 at 13:33
    
@michaelbn Yeah. That could work. –  Euphoric Oct 20 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.