I read an article talking about how to create domain objects here. The author is explaining how to design the classes. To put itin a nutshell, you have a class per real world entity (i.e class User, Comment, Post, etc) and getters + setters (that check the validity of the data).
For one to many relations, for exemple all the comments related to a single post, the author uses an array to store instances of the class Comment into an instance of Post class. But here is what i don't understand :
$post = new Post();
$post->addComment( new Comment() );
$post->addComment( new Comment() );
$post->addComment( new Comment() );
$postModel = new PostModel();
$postModel->insert( $post ); // Should also insert (or not !) the added comments.
When we're going to insert that new post, the associated comments may or may not actually exist (my example doesn't make a lot of sense since you can only comment posts that exist, but that's just an example). Should the model check each if the added comments exists before adding them ?
Also if you know an article that would explain how to write a model properly, in the same phylosophy used by the author of the article above, that would be nice.