Welcome Guest, Not a member yet? Register   Sign In
Datamapper (Find rows NOT in my join table)
#1

[eluser]Iverson[/eluser]
Say I have users can have multiple projects. How can I get the rows of projects that AREN'T related to a particular user?
#2

[eluser]tdktank59[/eluser]
well 1 option is to do something like this

Code:
$u = new User();
$u->where('id',$id);
$u->projects()->get();

foreach ($u->projects->all as $projects)
{
$project_ids = array($projects->id);
}

$p = new Project();
$p->where_not_in('id',$project_ids)->get();

see where im going with this?
#3

[eluser]Iverson[/eluser]
[quote author="tdktank59" date="1236738273"]well 1 option is to do something like this

Code:
$u = new User();
$u->where('id',$id);
$u->projects()->get();

foreach ($u->projects->all as $projects)
{
$project_ids = array($projects->id);
}

$p = new Project();
$p->where_not_in('id',$project_ids)->get();

see where im going with this?[/quote]

Thanks! I just needed to a jumpstart Smile Only thing I needed to change from your code was to make $project_ids an array instead of the object's id. This might be a good addition to Datamapper as I can see others using this just as much as relationships.

Code:
$u = new User();
$u->where('id',$id);
$u->projects()->get();

foreach ($u->projects->all as $projects)
{
$project_ids[] = $projects->id;
}

$p = new Project();
$p->where_not_in('id',$project_ids)->get();




Theme © iAndrew 2016 - Forum software by © MyBB