I have two entities related with many to one relation but each one belongs to a bundle.
When forcing the update in the database I get the following error
the target -entity cannot xxxx\Bundle1\Entity be found in xxxx\bundle2\entity
Any ideas please??
Just create an entity extending xxxx\Bundle1\Entity in your xxxx\bundle2 and make the relationship between two xxxx\bundle2 entities.
Related
I'm having an issue with single table inheritance and an optional many to one mapping on a sub class. When I try to load the parent entity through the child of a subclass the parent is loaded with no data. I can reload the entity and get data without issue, though. Here is a repository with an example:
https://bitbucket.org/GDIBass/relationalsingletableinheritancedoctrinebug
I've tried to recreate this in Doctrine ORM's test suite without any luck. Any ideas?
Try to use eager loading for 'fetch' option in your realtion.
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html
Hello I'm learning Symfony 3 and i Have this problem that I have an Entity Projects and an entity ProjectImages and relations is one to many.
Now I want to add f.e 4 images to one project and I don't know how to do it.
I read the documentation, how to add files etc. But how to add file in association in one FOrm where I create project ?
You should use form collection here is examples.
http://symfony.com/doc/current/cookbook/form/form_collections.html
I have an entity called Document. I'd like to make this entity related (many to one) to few other entities (let's say User, Invoice and Transaction). In Laravel I could easily achieve that by using polymorphic relations.
Is there any (easy) way to accomplish the same with Doctrine?
This might be what you're looking for http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html
Currently I'm working on doctrine module for favorites which can be reusable in any project and for any entity.
However there is problem with JOINs. I followed this article about dynamic mappings and it works great.. Well almost.
I've got User, Article and FavoriteItem entities, where Article entity can be added to favorites. Probably link to that github project with readme would be better (link).
The problem is mainly in that method which should return FavoriteItem by User and IFavoritableEntity, which in our example will be Article. As you can see, that method uses native query, but is it possible to use DQL? I know that I would have to use join to table without association, but it seems that doctrine can do that just for one-to-many/many-to-one associations.. I'm right? Or is there any other way how to do that in DQL?
Also do you think there is any way at all how to select in one query (DQL) all IFavoritableEntities by one User? I just can't imagine any.
Thank you
So I found other option which is add possibility to extend FavoriteItem entity where I'm able to add field with association to eg. Article::favorites field.
i ran into the following problem and after hours of searching on the web i don't find any solution.
I want to have a "3-Entity Relationship" between the Entity Project, User and Role.
A Project have many users, and a User can be member of many projects. But in every Relationship between Project <--> User the User can have a different Role.
How can i solve this with Doctrine2?
Many thanks in advance!
EDIT
An little codeexample would be very nice :)
You should have an N:M association between Project and User. Then every instance of this association has the role property (either as an integer for a fixed list, or as an association to a Role entity). Doctrine unfortunately does not explicitly support properties on associations, so in these cases you should use connector entities: an entity that is in ManyToOne connection to both Project and User. This entity then can hold the role value(s)/association(s), but you have to manage (dis)connecting through these objects.