Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm adds quote on query, how to escape that? Please suggest.
  • I am getting error on this. Orm adds quote on query which is causing the issue. Can I disable that? Can you please suggest me to resolve this?

      protected static $_has_one = array(
          'propertydate1' => array(
              'key_from' => 'id',
              'model_to' => 'Model_Propertydate',
              'key_to' => 'property_id',
              'conditions' => array(
                'where' => array(
                  array('FROM_UNIXTIME(propertydate1.date)', '>=', 'NOW()')
                )
              )
          )
      );

    I have stored date column as int in database. I need to use FROM_UNIXTIME to compare the date and get the data.
  • I have tries to use that, but it gives me error.

     protected static $_has_one = array(
          'propertydate1' => array(
              'key_from' => 'id',
              'model_to' => 'Model_Propertydate',
              'key_to' => 'property_id',
              'conditions' => array(
                'where' => array(
                  array(\DB::expr('FROM_UNIXTIME(propertydate1.date)'), '>=', 'NOW()')
                )
              )
          )
      );
  • HarroHarro
    Accepted Answer
    Ah, wait. You can't do that in a property, properties only allow scalar's.

    Use this instead:

    protected static $_has_one = array(
      'propertydate1' => array(
          'key_from' => 'id',
          'model_to' => 'Model_Propertydate',
          'key_to' => 'property_id',
          'conditions' => array(
          )
      )
    );

    public static function _init()
    {
        parent::_init();

        // define a dynamic where clause
        static::$_has_one['propertydate1']['conditions'][''where'] => array(
            array(\DB::expr('FROM_UNIXTIME(`propertydate1`.`date`)'), '>=', \DB::expr('NOW()'))
        );
    }

  • Got this error after using above code.

    Fuel\Core\FuelException [ Error ]:

    Invalid method call. Method _init does not exist.
  • Remove the parent call, if your parent class doesn't have an init method.

    I've copy/pasted this from one of our models, which are have a base-class, might have copied a bit too much. ;-)

Howdy, Stranger!

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

In this Discussion