Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using MONTH() and DAY() in find()
  • I need the Orm to return events in a given month, so I'd normally use the MySQL command
    SELECT * FROM events WHERE MONTH(date) = '$month'

    Here's my attempt at using the Fuel Orm:
    $events = Model_Event::find('all', array(
     'where'  => array(
      array('MONTH(start)', $month)
    Obviously, that doesn't work. How might I get it to work?
  • Try this:
    'where' => array(
        array(Db::expr('MONTH(start)'), $month),
  • Thanks for the suggestion, but it always returns "Argument 1 passed to Orm\{closure}() must be an array, object given"
    array(DB::expr('MONTH(start)'), '>', date("n"))
    array(DB::expr('UNIX_TIMESTAMP(start)'), '>', time())
    array(DB::expr('UNIX_TIMESTAMP(start)'), time())

    None of those work!
  • the same error here ErrorException [ 4096 ]: Argument 1 passed to Orm\{closure}() must be an array, object given, called in /home/html/ on line 135 and defined
    PKGPATH/orm/classes/query.php @ line 123
    Backtrace COREPATH/bootstrap.php @ line 54
    PKGPATH/orm/classes/query.php @ line 123
    PKGPATH/orm/classes/query.php @ line 135
    PKGPATH/orm/classes/query.php @ line 135
    PKGPATH/orm/classes/query.php @ line 146
    PKGPATH/orm/classes/query.php @ line 30
    PKGPATH/orm/classes/model.php @ line 399
    PKGPATH/orm/classes/model.php @ line 353
    APPPATH/modules/mod1/classes/controller/myfile.php @ line 57
    COREPATH/classes/request.php @ line 426
    DOCROOT/index.php @ line 42
  • If I interpret the docs correctly, the syntax should be
    Model_Something::find('all', array('where' => array(array(DB::expr('MONTH(start)'), '>', date("n")))));
  • yes, but DONT WORK. core 1.1 devel / orm 1.1 devel
  • Tried it, and indeed, it only supports strings at the moment. Which means this should work:
    Model_Something::find('all', array('where' => array(array((string) \DB::expr('MONTH(column)'), '>', date("n")))))
  • That still sends a string to the Orm, so it returns "Unknown column 't0.UNIX_TIMESTAMP(start)' ", it would need to be UNIX_TIMESTAMP(t0.start)? Shall I open a ticket on GitHub?
  • Probably best, the Query class needs native support for DB::expr to deal with this properly.
  • its working in 1.1 with find() ->where(\Fuel\Core\DB::expr('MONTH(column)'), '=', 10) but not INside find( ... )

Howdy, Stranger!

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

In this Discussion