I need my model to return only those records from one table where a matching record does not exist in another table. I was thinking that the solution might be with Query Scopes but the documentation only scratches the surface. So my SQL would look something like this:
SELECT *
FROM A
WHERE NOT EXISTS (SELECT A_id FROM B
WHERE B.A_id = A.id)
Here are my tables:
A
-------------
| id | name |
-------------
B
--------------------
| id | A_id | name |
--------------------
Probably unnecessary but here are my models. Model for A:
class A extends Eloquent{
public function B(){
return $this->hasOne('B', 'A_id', 'id');
}
}
Model for B:
class B extends Eloquent{
public function A(){
return $this->belongsTo('B', 'A_id', 'id');
}
}