We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Started to work with Devtools

So, it has been a year since I lastly used Phalcon. Now I want to work again on it, this time doing it right, so I'm starting using the devtools. It isn't something new to me, but when I came to the models part I had a question: I've to had the tables created in the DB? Because using phalcon model requires having the actual table in the DB (for example, in Django you don't have to have then created before).

I don't know if in the video says something, because of my low internet speed.

Error trace:

phalcon model user --get-set --doc --trace
Phalcon Devtools (2.1.0 RC 1)

    Error: Table "user" does not exist.


5.7k

When you create models with DevTools, it will read your table schemas and create a model to match each tables. You can do this one table at a time using phalcon model table_name [optional flags here] or you can do them all at once using phalcon all-models [optional flags here].

If you use foreign keys in the table schemas, devtools will automatically map the relationships as well. This is extremely convenient. There is also an option flag to map the foreign keys to the models to enforce them at the code level.



33.8k

When you create models with DevTools, it will read your table schemas and create a model to match each tables. You can do this one table at a time using phalcon model table_name [optional flags here] or you can do them all at once using phalcon all-models [optional flags here].

If you use foreign keys in the table schemas, devtools will automatically map the relationships as well. This is extremely convenient. There is also an option flag to map the foreign keys to the models to enforce them at the code level.

Yes, I know that for what I tried and read, but that isn't what I'm asking.

I'm asking if I've to manually create the tables in the DB before creating the models. I don't see it convenient. You could be able to create the models and then migrate those models to SQL. Later, you would use the generated SQL script to create the tables inside the DB.

No you have to create the table manually.

I can think of a few PHP frameworks that don't have this functionality, but some do, like Symfony+Doctrine.



33.8k

Mmm well, ok, thanks both for the info.