Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Including an expression in a related query
  • Trying to send a DB expression as an array in a related model.

    Model_Market::find($market, array(
    'related' => array(
    'events' => array(
    'where' => array(
    array(Db::expr('YEAR(`date`)'), '=', $year),
    ),
    ),
    ),
    ))
    Returns: Argument 1 passed to Orm\Query::_parse_where_array() must be of the type array, object given

    Swapping `array(Db::expr('YEAR(`date`)'), '=', $year)` for `array('date', 'LIKE', $year.'%')` works but isn’t very efficient.
  • Hi,

    I suggest you to use Db::expr() with query function.


    Model_Market::query()
    ->related('events', array('where' => array(array(\Db::expr('YEAR(`date`)'), '=', $year))))->get();

Howdy, Stranger!

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

In this Discussion