Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
2 unexplained properties of ORM relations
  • I was reading the doc's and came across this snippet:
    // in a Model_User which has one profile
    protected static $_has_one = array(
    'profile' => array(
    'key_from' => 'id',
    'model_to' => 'Model_Profile',
    'key_to' => 'user_id',
    'cascade_save' => true,
    'cascade_delete' => false,
    )
    );

    And my question is: what do the "cascade_save" and "cascade_delete" properties do?
  • cascade_save: if true, when saving the object, it also saves updated related objects
    cascade_delete: if true, delete related objects when deleting the object itself
  • And if I use FOREIGN KEYS on tables I can ignore this 2 keys right?
  • No. The key fields in the relationship definition are used to generate the SQL for the joins, so they are required.
  • Disable both if you are using foreign keys with sql cascading, that's superior though will not be reflected during runtime (objects won't perish, though the relation between them will be broken).
  • What do you suggest, cascading with ORM or Foreign Keys?
  • I prefer the SQL, but the downside I mentioned is an important one to understand and be aware of.
  • Harro Verton wrote on Friday 23rd of December 2011:
    No. The key fields in the relationship definition are used to generate the SQL for the joins, so they are required.

    Oops, sorry, I thought you referred to the 'key' fields in the definition. But you meant the cascade settings...
  • Thanks for the replies!

Howdy, Stranger!

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

In this Discussion