Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
single modal with dual relation
  • i have a modal A & B & C

    Modal A has many rows in B related by a column in B as 'A_id'
    Modal C (related to A)has many rows in B related by column in B as 'C_id'

    both has only one row in B, !!! the combo of both will be one row. how i select the single row if i know

    how i implement it using fuelphp?

  • anybody please
  • HarroHarro
    Accepted Answer
    See if I understand the question:

    A => B
    A => C => B

    And you want to know which B is related to both A and A => C?

    In these cases, always try to think of how you would write the SQL to produce the required result. And if you have it, convert it to code.

    For the ORM, both "B"'s are different collections, so if you need to know which B is related to both, you need to fetch both collections, and do an array_intersect().
  • i getting an error like this,

    ErrorException [ Fatal Error ]:
    Object of class Model_Measurement could not be converted to string

    i found no errors to produce this issue. but it happens.

    <?php
    $measure = array_intersect($student->measurements,$product->measurements);
    if(count($measure) != 0){
    \Debug::dump($measure);
    }
    ?>
    http://bin.fuelphp.com/snippet/view/L6
    this is my view.

    in the loop you see, one result has same array with same object id. where as another result has different object id, so in second one i need null result in array_intersect. but i getting fatal error.
  • If you know how array_intersect works, you'll notice it will intersect on the array's values. That means in your case, that each Model_Measurement will be cast to a string. However, it cannot be converted because there is no method __toString() on any Orm\Model. Thus, array_intersect will fail.

    You'll need to look into other array_intersect functions. Head over to php.net and find out, what over functions there are of which one will be the one you need (has something to do with the array's keys not its values).
  • Sorry about that, was on the road, had to reply from memory... ;-)
  • OK, It is OK

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion