Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Cascading deletes and other FK functionality
  • Hello,

    I've been looking into Fuel for a bit now but have questions now that I would like to use it on a first major project.

    Firstly, when setting up the models, I see you can do one-to-many and other normal joins. When you do this, can fuel create the tables automatically and create the FKs as well?

    When I save a model instance, will any necessary child objects or properties update as well?

    If i delete a parent object, will it delete the child ones?

    If i try to save a new object and a child save fails will it fully roll back?

    I used grails for a while and you just had to create the models with the 'belongs to', 'has many' properties and the tables were created and setup automactially on deployment and records were managed through the framework itself.

    I'm hoping this is something that is possible for fuel to do on its own.

    I know i can setup the tables with the FKs by hand, but would prefer to skip the step if possible.

    Thanks.

  • Lots of questions in a single post...

    1. No, Fuel can not generate tables from models. Fuel uses migration files for database changes. You can use the "oil" commandline utility to generate both the model and the corresponding migration file.
    2. If you have enabled "cascade_save" on the relation, yes. And the default is "yes".
    3. If you have enabled "cascade_delete" on the relation yes. The default here is "no".
    4. No, unless you enable transactions. You can do that per save operation by passing "true" as second parameter on the parent->save() call.

    We are "obsessed" by performance, so in general any magic and wizardry in the code that is not required on every page load will not make it into the framework.

    Checking if tables exist, and if they have the correct structure, is a very time consuming operation, so something you absolutely don't want to do on every page load.

    The setup of the database in FuelPHP is done through migrations, which are run from the commandline using "php oil refine migrate --all".

Howdy, Stranger!

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

In this Discussion