I have a many-to-many relationship created using fuelphp's ORM.
The pseudocode for the relation looks like this
class MyModel extends Model
{
protected static $_many_many = [
'relatedmodel' => [
'conditions' => [
'where' => [
['ctime', '>', DB::expr(('now() - interval 1 week'))],
],
],
]
];
}
The idea here is that I only want the relationship to look at newer relatedmodels that were created in the last week.
However, this obviously won't work because of a php language constraint - an expression is not allowed as a field default value.
How can I get the desired behavior in FuelPHP despite that constraint?
The work around for the language constraint here is to use Fuel autoloader's public static _init()
function to set the value. This gets called automatically when the class is loaded by the autoloader.