Reputation: 1241
I've recently inherited a bunch of Symfony2 apps from a former colleague. I've played with Symfony2 enough to where I understand the basics of what is going on from the Acme demo. My boss wants me to start looking at some of the code he has written as some things need to get updated right away. I should note, I started on a fresh install of symfony and have started to go in and recreate what I see on my own -- at each point I'm looking at how I did it compared to what my former colleague did.
I'm at the point now where I need to create entities from the established database. I've set the database configuration in app/config/parameters.yml
What is the best way to create the entities now to match the database? I've use php app/console generate:doctrine:entities
but after I type all the fields out, I keep getting a matching error where symfony will look for "status_id3" instead of just "status". Here is the error I'm getting:
An exception occurred while executing 'SELECT t0.id AS id1, t0.library_id AS library_id2, t0.status_id AS status_id3, t0.name AS name4, t0.total AS total5, t0.available AS available6, t0.in_use AS in_use7, t0.offline AS offline8 FROM Lab t0 ORDER BY t0.name ASC':
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'labstats.Lab' doesn't exist
Many thanks for your help!
Upvotes: 0
Views: 132
Reputation: 16502
Doctrine is a Database Abstraction Layer. This means all of the code that you write involving Doctrine entities and getter/setter functions are a high-level abstraction of what Doctrine actually queries MySQL for (with AS
statements and highly unique names, along with fetching the ID of objects instead of the actual object, which would only get loaded lazily.)
There's a lot of details to all of this that you can learn on your own from the Doctrine documentation, but this is a quick synopsis.
Either way, you're misinterpreting the MySQL error. Why would you think that MySQL is complaining about t0.status_id AS status_id3
when the error clearly states that the entire table labstats.Lab
doesn't exist? The likely culprit is that your database schema doesn't match the metadata of the Doctrine Entities.
The doctrine:generate:entities
command will happily create your getter/setter functions for you automatically, but the database schema isn't touched until you run doctrine:schema:update
from your console as per this documentation. Without the --force
flag, Doctrine will just verify the schema and let you know the number of SQL queries that need to happen to update the schema (with the option to see them using --dump-sql
.) With the --force
flag, Doctrine will run them for you (which is not recommended on a production environment. Instead you should use migrations.)
Upvotes: 1