Database Table inheritance in Doctrine
Have you came across a situation when you need to apply Object Oriented Inheritance principle in database design? Did you have two tables sharing some fields and you wanted to connect them together without having to run queries or parallel insertion? Search no more as Doctrine supports this using Class Inheritance with discriminatorMap.
At the end of this post, you’ll learn how to create a product table (super class) and 3 different product category tables (furniture, food, online downloadable items) that inherent product table so when you insert a new furniture item, it will save same id, price to product table as well.
Doctrine load fixtures – How to load particular fixture
Symfony has an option to load fixtures from command line:
$ php app/console doctrine:fixtures:load --help
doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="..."] [--purge-with-truncate]
--fixtures The directory or file to load data fixtures from. (multiple values allowed)
--append Append the data fixtures instead of deleting all data from the database first.
--em The entity manager to use for this command.
--purge-with-truncate Purge data by using a database-level TRUNCATE statement
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
--shell (-s) Launch the shell.
--process-isolation Launch commands from shell as a separate process.
--env (-e) The Environment name. (default: "test")
--no-debug Switches off debug mode.
But if you assign the full path to fixture file with
--fixtures option, its not going to load it and you’ll end up with error:
Could not find any fixtures to load in:
The other option is to load the folder itself by typing the full path to
folder where fixture file resides.
php app/console doctrine:fixtures:load --fixture=/src/BundleName/DataFixtures/ORM/