Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Model code generation from database?
  • I see a page here can generate ORM Model code by providing the fields to oil package:

    But is there a way I could connect to database directly and generate the ORM Model code including all those primary key, relationship etc?

    I am thinking I may just create a code generator one with C# ....
  • HarroHarro
    Accepted Answer
    There is a task called fromdb:

    php oil refine fromdb:help

    which can generate both models and scaffolding from an existing table (or multiple tables).

    Note that this works best with MySQL or MariaDB, other databases may not return enough information to generate it properly.
  • Note that it does not generate relations, there is no way it can reliably determine the relations between two tables.
  • Isn't using the following to query foreign keys can construct the relation between tables?
    Currently that's how I customize and generate the relationship for has_many and has_one.
    Or did I missing anything I should concern?

  • Don't know.

    Most people don't implement database constraints as it may interfere with the ORM's workings (especially when you use cascading deletes), and it is also very RDBMS specific, so it can't be implemented in the drivers which at the moment are generic.

    If it works for you, I'd say use it.

Howdy, Stranger!

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

In this Discussion