Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Generate relationship with oil refine fromdb:model
  • When I read the orm documentation, the relationship part confused. Should key_from be the property on the present model or the model being linked to? same as key_to but when I saw that the command oil refine fromdb:model can help generate the model I was happy, thinking it'll help me automatically handle the relationships because I already set it up at the database but unfortunately it didn't.

    Data type and validation weren't generated either. It will be nice if future version of oil can properly generate complete models.

    Also oil refine fromdb:model --all didn't work, I had to specify the tables individually.

    As for the orm it looks confusing to me, maybe I'll just stick to writing good 'ol sql.
  • "from" is the model itself, "to" is the model you link to. Also pay attention to "belongs_to" relations, and make sure you define them correctly. A rule of thumb: you use "belongs_to" for the model that contains the foreign key.

    Unfortunately it is (virtually) impossible to generate data type. validation and relations from the database. Most databases only give partial data, some don't give any useful details at all.

    The database drivers were originally written for MySQL, and only in recent versions there is support for others through PDO. And only in the last release we've started to replace the hardcoded schema commands with separate classes per database type.

    The ORM is so complex that making major changes to it is not really doable. For the next major version of Fuel, the ORM will be rewritten, using a new underlying database layer, to address these issues.

    The framework has been designed around models and migrations, so generating and maintaining your database from your code, and not the other way around. The FromDB task was contributed much later by a user, to be used as a tool when you have to convert an existing application.
  • Oh I see though the project I'm working, the database will be created after installation and I don't think it's possible for me to run migration from within php instead of using oil that's what made me manually create the database.

    I think it will be better for me to just stick to sql.
  • Yes, you can.

    We also have CMS type applications in which the webmaster runs updates including migrations from the web admin interface.

    Have a look at the Migrate class, the oil script calls that to run the migrations.

Howdy, Stranger!

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

In this Discussion