You know, you could just move all of your SQL out of that AR object and into the Collection...inghamn wrote:I've been going the route of Active Record + Collections. The collection classes are where we can put all the SQL needed to handle returning a bunch of Active Record objects. With a flexible find function, you can do just about anything you want. And if there's some reporting you just can't figure out how to do with the Active Record object or the Collection's find function, you can admit defeat, and just write your own static function into the collection class to do whatever.
Interesting. What is it about a 'custom mapping system' that you feel would bog you down?inghamn wrote:Well, that's all I can think of right now. I've actually left relations off the list. I'm not sure I want to get bogged down in some custom mapping system from an ORM. The relationships fall into the easy stuff category, and best left to the developer.
Is this how you'd do relationships? (Assuming a DataMapper):
Code: Select all
$author = $userMapper->findById (10);
$posts = $postMapper->findByAuthor ($author);
foreach ($commentMapper->findByManyPosts ($posts) as $comment) {
$comments[$comment->getPostId()][] = $comment;
}
foreach ($posts as $post) {
$post->setAuthor ($author);
$post->setComments ($comments[$post->getId()]);
}