Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Adding relations dynamic if module exists
  • Hey is there a simple solution to add relations in a model in the constructor at example? The following code:
    public static function forge($data = array(), $new = true, $view = null) {
            if(\Module::exists('dashboard')) {
                static::$_many_many = array_merge(static::$_many_many, array(
                    'dashboard_items' => array(
                        'model_to' => 'Dashboard\Model_Dashboard_Item',
                        'cascade_save' => true,
                        'cascade_delete' => true,
                    )
                ));
            }
            return parent::forge($data, $new, $view);
        }
    

    will output the following error exception:
    OutOfBoundsException [ Error ]: Property "dashboard_items" not found for Users\Model_User.
    
  • The ORM Model heavily caches data, including processed relation definitions. So if this is not the first instantiation of this class, the relations are already processed and in cache. Subsequent calls will not check the properties again, but load the info from cache. However, this relation isn't in it. It might work to reset the cache after adding the new relation:
    $class = get_called_class(); if ( array_key_exists($class, static::$_relations_cached)) { unset(static::$_relations_cached[$class]); } [code] which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    $class = get_called_class();
    if ( array_key_exists($class, static::$_relations_cached))
    {
    unset(static::$_relations_cached[$class]);
    }
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.
  • The ORM Model heavily caches data, including processed relation definitions. So if this is not the first instantiation of this class, the relations are already processed and in cache. Subsequent calls will not check the properties again, but load the info from cache. However, this relation isn't in it. It might work to reset the cache after adding the new relation:
    $class = get_called_class(); if ( array_key_exists($class, static::$_relations_cached)) { unset(static::$_relations_cached[$class]); } [code] which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    $class = get_called_class();
    if ( array_key_exists($class, static::$_relations_cached))
    {
    unset(static::$_relations_cached[$class]);
    }
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.
  • The ORM Model heavily caches data, including processed relation definitions. So if this is not the first instantiation of this class, the relations are already processed and in cache. Subsequent calls will not check the properties again, but load the info from cache. However, this relation isn't in it. It might work to reset the cache after adding the new relation:
    $class = get_called_class(); if ( array_key_exists($class, static::$_relations_cached)) { unset(static::$_relations_cached[$class]); } [code] which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    $class = get_called_class();
    if ( array_key_exists($class, static::$_relations_cached))
    {
    unset(static::$_relations_cached[$class]);
    }
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.
  • The ORM Model heavily caches data, including processed relation definitions. So if this is not the first instantiation of this class, the relations are already processed and in cache. Subsequent calls will not check the properties again, but load the info from cache. However, this relation isn't in it. It might work to reset the cache after adding the new relation:
    $class = get_called_class(); if ( array_key_exists($class, static::$_relations_cached)) { unset(static::$_relations_cached[$class]); } [code] which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    $class = get_called_class();
    if ( array_key_exists($class, static::$_relations_cached))
    {
    unset(static::$_relations_cached[$class]);
    }
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.
  • The ORM Model heavily caches data, including processed relation definitions. So if this is not the first instantiation of this class, the relations are already processed and in cache. Subsequent calls will not check the properties again, but load the info from cache. However, this relation isn't in it. It might work to reset the cache after adding the new relation:
    $class = get_called_class(); if ( array_key_exists($class, static::$_relations_cached)) { unset(static::$_relations_cached[$class]); } [code] which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    $class = get_called_class();
    if ( array_key_exists($class, static::$_relations_cached))
    {
    unset(static::$_relations_cached[$class]);
    }
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.[code]
    which will trigger a rebuild of the relation cache for this class when the relations() method is called.

Howdy, Stranger!

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

In this Discussion