Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Orm adds quote on query, how to escape that? Please suggest.
idoweb9
August 2017
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.
Harro
August 2017
Accepted Answer
Have a look at
https://fuelphp.com/docs/classes/database/db.html#/method_expr
idoweb9
August 2017
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()')
)
)
)
);
Harro
August 2017
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()'))
);
}
idoweb9
August 2017
Got this error after using above code.
Fuel\Core\FuelException [ Error ]:
Invalid method call. Method _init does not exist.
Harro
August 2017
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.
;-)
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
August 2017
idoweb9
August 2017