Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]WanWizard[/eluser]
[quote author="Maglok" date="1348481921"]Class Organisation has many Class CCClass
Class CCClass has many Class Feature

I want the features that CCClass has to be limited to the features denoted by the count column in class Level.[/quote]
How does CCClass relate to Level? That isn't mentioned anywhere.

[eluser]Maglok[/eluser]
Level = Organisation, apologies.

[eluser]WanWizard[/eluser]
@rick20,

Try to avoid iterating over a resultset, as that will produce N+1 queries.

Instead, select all departments, and then run a where_in($departments) query, it will use the id's of the resultset to select all records related to those departments.

[eluser]rick20[/eluser]
@WanWizard ah..thanks for the correction Smile
But I thought before get() is called, there's no query executed, isn't it? (CMIIW).
And yeah, I just realized that we can use where_in($departments). Thanks for the advice Smile

Btw, do you have any idea with my issue here: http://ellislab.com/forums/viewthread/20...0/#1031471

Kindly advice.
Thanks

[eluser]matyhaty[/eluser]
@WanWizard @rick21

Thanks for that - which worked, by doing the following:

Code:
$dd = new Department();
$dd->where('id', 1);
$dd->or_where('id', 2);
$dd->get();

$tt = new Task();
$tt->where_in_related($dd, 'state', 'Active');
$tt->get();

Do you have to specify a column to use (not a problem, as I have state for all tables, just wondering....

However when changing them together - it didn't seem to work Sad
I made up a little example, which is fairly long handed written:

Code:
public function tester()
{  
  echo '<hr>Departments Checker<br/>';
  $dd = new Department();
  $dd->where('id', 1);
  $dd->or_where('id', 2);
  $dd->get();
  
  foreach($dd as $r)
  {
   echo $r->id .' - '.$r->title .'<br/>';
  
  
   // DEpartments
   $ddc = new Department();
   $ddc->where('id', $r->id);
   $ddc->get();
   $ddc->task->get();
   echo '<i>Which has related Task:</i>';
   echo '<ul>';
   foreach($ddc->task as $task)
   {
    echo '<li>'.$task->id.' </li>';
   }
   echo '</ul>';  
  
  }
  
  //--------------------------------------------------------------------------------
  echo '<hr>Depot Checker<br/>';
  $dp = new Depot();
  $dp->where('id', 104);
  $dp->get();
  
  foreach($dp as $r)
  {
   echo $r->id .' - '.$r->title .'<br/>';
  
  
   // DEpots
   $ddp = new Depot();
   $ddp->where('id', $r->id);
   $ddp->get();
   $ddp->task->get();
   echo '<i>Which has related Task:</i>';
   echo '<ul>';
   foreach($ddp->task as $task)
   {
    echo '<li>'.$task->id.' </li>';
   }
   echo '</ul>';  
  
  }
  
  //----------------------------------------------------------------------------------
  echo '<hr> Tasks which are related to any of the departmentments and depots:<br/>';
  
  $tt = new Task();
  $tt->where_in_related($dd, 'state', 'Active');
  $tt->where_in_related($dp, 'state', 'Active');
  $tt->get();

  foreach($tt as $r)
  {
   echo $r->id .' - '.$r->title .'<br/>';

  }
}

which produces the following output:

Code:
Departments Checker
1 - Operations
Which has related Task:

    78
    84

2 - Processing
Which has related Task:

    83

Depot Checker
104 - Irlam
Which has related Task:

    84

Tasks which are related to any of the departmentments and depots:
78 - The Night Shift
83 - October Desilts Trafford
84 - Oct Desilts South Lakes

I was expecting the only resulting task to be task ID 84, as that is both related to a depot and department

Any ideas?

Thanks


[eluser]WanWizard[/eluser]
[quote author="Maglok" date="1348555964"]Level = Organisation, apologies.[/quote]
Ah, ok.

Sounds a bit similar to the other "question of the day".

I think I would something like
Code:
$ccclass = new CCClass();
$ccclass->where_related_organisation('level', 4)->get();

$feature = new Feature();
$feature->where_in_related_ccclass($ccclass)->get();
which should give you all features that are related to ccclasses that are related to organisations with a level of 4.

[eluser]WanWizard[/eluser]
@matyhaty,

A "SELECT * FROM table WHERE id IN (x,y,z)" is always an OR, not an AND.

[eluser]matyhaty[/eluser]
Is there a way of doing an AND, or some sort of merge on two seperate result sets (even if that result set is just a load of ID's that would do!)

[eluser]Maglok[/eluser]
It does seem to be the question of the day Smile

I just wondered if it was possible to do a relationship between the two that is a 'simple' has_many or has_one and does not require me to change the getting of the class. Regardless this does anwser the question and I'll just stick with the functions that do what you are suggesting for me. Smile

Keep up the good work wizard!

[eluser]rick20[/eluser]
@WanWizard do you have any suggestion of how to select rows from a table that have many-to-many relationship with other table, filtered by a field in join-table?

You can refer to this post for the codes
http://ellislab.com/forums/viewthread/20...0/#1031471

So far I already tried the followings with no luck:
Code:
$user = new User(1);
$user->ordered_item->where_join_field('ordered_user', 'status', 'active')->get();

$item = new Item();
$item->where_join_field('ordered_item', 'status', 'active')->get();
$item->where_join_field('ordered_user', 'status', 'active')->get();
$item->where_join_field($user, 'status', 'active')->get();

Really need help.
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB