I have created a Entity with name "InventoryVenue" for the table "Inventory_Venue".
When I'm trying to insert data, entity manager pointing to "InventoryVenue" instead of "Inventory_Venue" which is not exists in database.
This is my entity
This is my code
Here entity not pointing to the actual table.
Related
I am implementing horizontal sharding of my database in my Symfony application. I have a method to create a table based on the "template" Entity I've made. For example, my Entity "AnswerData" will be used to create tables such as "AnswerData_sourceA", "AnswerData_sourceB"... and so on that are exact same schemas as the entity-based "AnswerData". While I have the database tables created already, I'm not quite sure how to get Symfony and Doctrine to designate which table I want the Entity to be created/saved to.
For example:
$em = $this->getDoctrine()->getManager();
$answerData= new AnswerData();
$answerData->setData();
//Set other properties...
...
$em->persist($answerData);
$em->flush();
$em->clear();
The above would have Symfony/Doctrine save the Entity to "AnswerData" table, but I am not sure where/how to tell it to save it to the "AnswerData_sourceA" table. Should I be writing custom repository classes that handle this or can the above snippet be modified to manually set the table? Thank you for any advice!
If I understood you want to save to specified table. you need
/**
* #Entity
* #Table(name="AnswerData_sourceA")
*/
to specify that name like this.
With Doctrine 2, is it possible to add a new property to an entity to persist it in the entity manager, but NOT create a new column in the database ?
Purpose of that is to add a explain field to an entity and catch it with an event when UnitOfWork detects an update of one entity's value. (and perhaps send the content of the explain field by email, or log it, ...)
But I don't want to store this value in the database.
I'm working on a import function that receives mapped data. The data is mapped by database column names for the target system. The application is symfony2 and uses doctrine to manage the database.
The problem is, most of the entity property names are different from the column names. I was wondering if there is a way to get the property by column name. Else i'll have to update the database without using the enities, or create another mapping.
Cheers,
Tim
Go through this class,
http://www.doctrine-project.org/api/orm/2.2/source-class-Doctrine.ORM.Mapping.ClassMetadataInfo.html
getFieldName() method, you can get field names.
How can i set up just one DB table for addresses, and have both company and user entities access it? Or would I have to set up a separate address table for each? thx!
Yes. Just add the same Many-To-One association to Address on both the User entity and the Company entity.
I have a database and i generate entities using DisconnectedClassMetadataFactory and EntityGenerator. Indeed, metadata driver do not create associations, because column names in db are not well named (basically, it's id_ as primary id and a reference in other tables). How can I change behavior of metadata factory or treat metadata info after to add those associations?