add prefix in table name without change in annotation of Doctrine - php

I am using Doctrine2 with codeigniter. my project has created but i have to add prefix in database table. In codeigniter I have solved this issue with dbprefix $db['default']['dbprefix'].
But Doctrine not support it because Entity classes are not created with prefix. So it can't find Table.
I want to add table prefix in doctrine also without change in Entity class name of doctrine. Is there any possibility to add some prefix.
I have search TablePrefix Class but this class not working in my Doctrine library.
Previously Project created without prefix table name like "user" and entity annotation has also created with "User". But now I added prefix in all table "my_user"
Please Help!!

You can add a table prefix by using Doctrines event manager as described in the Doctrine documentation here:
http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/cookbook/sql-table-prefixes.html
In a previous question, simshaun has given a good example of how to implement this in symphony:
How to setup table prefix in symfony2

Related

Create an entity from an existing database, but tables are missing

I have created my database in Symfony with
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
I have created my repository too.
But when I look at the entity directory, one important table is missing.
In this table there is a lot of important information for my website, but I can't access it, because the entity does not exist.
I have no error with the import and not error in the database (I think).
Table on HeidiSQL:
The entity on the Symfony web site:
I have not demande_etape.
Why and how i can make this table in entity ?
I don't no why but if symfony not detect ID key, he can't import the table and make joins in table on both side.
So I created my entity myself and i put id_Demande field and id_Etape field in ID.
It's wotking !

How to extend symfony entity in bundle

Is there a way I can extend a symfony entity in another bundle using #DiscriminatorMap without having to specify it beforehand?
BundleA
Has a class AbstractQueueItem which is a MappedSuperclassfor
Event which is extended by
CreateEvent and DeleteEvent as Single Table Inheritene or Class Table Inheritence
BundleB
How can I add a new Event (i.e. UpdateEvent) to the Event-hierarchy without modifing BundleA?
You can try letting doctrine auto-generate the discriminator map.
From the last bullet point in this section of the docs:
If no discriminator map is provided, then the map is generated
automatically. The automatically generated discriminator map contains
the lowercase short name of each class as key.
So you would:
Omit the #DiscriminatorMap declaration in BundleA.
Extend the entity as normal in BundleB (making sure the short name of each class is unique).
Update the database schema.
EDIT
As pointed out by ju_ in the comments, this solution will apparently not work with Doctrine ORM 3.0, but should still be valid for versions 2.5 - 2.7

Symyfony 3.4 - How to move entitiy to other database

I am running a Symfony 3.4 based web service using Doctrine to manage and persist the different data entities.
Now I am trying to implement a method which transfers older, abandoned user accounts to another database which acts as archive.
Regarding to the Symfony docs it should be no problem to configure Doctrine to manage different database connections and entity managers.
However I do not completely understand the process on how to setup this use case:
Assume the Symfony project has different data entities DataEntity1, DataEntity2, etc. and different infrastructure entities Infrastructure1, etc..
How to tell Doctrine to initialize the archive DB with the data entities only?
How to move the entities between the DBs? Is loading them from entity manager 1 and persisting them in entity manger 2 the correct way?
Is there any best practice on how to do this?
If I understand your question correctly, you should use the prefix option for the mapping configuration.
prefix
A common namespace prefix that all entities of this mapping share.
This prefix should never conflict with prefixes of other defined
mappings otherwise some of your entities cannot be found by Doctrine.
This option defaults to the bundle namespace + Entity, for example for
an application bundle called AcmeHelloBundle prefix would be
Acme\HelloBundle\Entity.
Have a look at https://symfony.com/doc/3.4/reference/configuration/doctrine.html it shoul help you.
To move the entities between the two DBs, you should have two entity managers and use the correct one to persist olders accounts.
Hope this helps.

Symfony3, creating entity without mapping all table fields

I have a database table which has a lot of fields. I want to create an Entity which maps only to few of those fields.
Is there a practical way to achieve that?
When I try to make an entity and mapping it via annotations, the doctrine:schema:validate command says that the entity is not in sync, and is right.
When I try to make a doctrine:schema:update it automatically drops all the fields that the entity doesn't have. I want that the schema update command updates only the fields written in my entity class.
With Doctrine ORM you map your database table to a PHP class and a row from that table is mapped to an instance of the entity class.
So i am pretty sure that you have to map all your fields. Otherwise if you dont want to - user ActiveRecord, it is possible there.

Remove mapped doctrine field of parentclass in Symfony [FOSUserBundle]

How is it possible to remove a field that got inherited as doctrine column from mapping?
Example:
In FosUserBundle, I don't need some of the columns (e.g. salt, expiresAt...) within my User class. How can I tell symfony/doctrine to not map this column anymore to the database / remove it from the mapping? I know how to "reconfigure" the columns by using #AttributeOverride, but how can I completly remove a field from the mapping?
Regards.
Pretty much all default properties of the FOSUB User entity are mandatory to make the bundle working as expected.
The fields you given (salt, expiresAt) are related to the security, as the most part of the User properties.
Remove one of them may have side effects in your user management.
Also, you can't Selectively inherit parts of an entity.

Categories