[eluser]Genki1[/eluser]
How do I get all the Books which are
not related to a specific User. The relationship is Many to Many.
The following query works, but is it the best way to accomplish the query?
Code:
$u = new User(1); // get user id #1
$b = new Book;
$b->where_not_in_related('user', 'id', $u->id);
$b->or_where_related('user', 'id', NULL);
$b->get_iterated();
I derived the above from these two queries which get close to the desired result but are not exactly what I want:
Code:
// finds Books related to Users other than user #1 (but excludes Books which have
// no relations to any User at all):
$u = new User(1); // get user id #1
$b = new Book;
$b->where_not_in_related('user', 'id', $u->id);
$b->get_iterated();
Code:
// finds Books not related to any User at all (but excludes Books which have
// a relation to one or more other Users):
$u = new User(1); // get user id #1
$b = new Book;
$b->where_related('user', 'id', NULL);
$b->get_iterated();