Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
$query->related() calls
  • Hello,

    Quick question - In the documentation (http://fuelphp.com/docs/packages/orm/crud.html) there is a sample call:
     
    Model_Article::query()->related('author', array('where' => array('active', '=', 1)));

    This produces the following error: ErrorException [ 4096 ]: Argument 1 passed to Orm\Query::_parse_where_array() must be an array, string given, called in /fuel/packages/orm/classes/query.php on line 478 and defined

    This is a sample that was found to work: 
    $query->related('author', array('where' => array('active' => 1)));

    Is this an error in functionality, outdated documentation, or am I doing something wrong?

    Thanks!
  • HarroHarro
    Accepted Answer
    As things stand at the moment, it's a typo, and the code expects your second example.

    But in my opinion this is incorrect, as that syntax doesn't allow you to insert a where clause other then "is equal". Which means the code needs to be adapted to accept what is documented.

    Can you create an issue for this on http://github.com/fuel/orm/issues so it can be looked at?
  • I had the same issues.The solution is to replace array('where' => array('active', '=', 1)) by array('where' => array(array('active', '=', 1))) in your query!
    so your query became like that:
    Model_Article::query()->related('author', array('where' =>array( array('active', '=', 1))));
  • That works too, but I find it not intuitive to pass an array in an array, it would be more logical to keep the same way or working as with the chained methods.

Howdy, Stranger!

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

In this Discussion