Doctrine2 and polimorphic relationship - php

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

Related

How to create an Entity with multiple tables? (Doctrine2)

There is a legacy project, which I would like to refactor. I would like to handle all database related stuff with Doctrine.
Unfortunately the user data is in two tables. There is a x_users and a x_userdata table. Both have a user_id field, but store different type of information. I would like to use all the columns from both tables in my User entity. How is it possible?
I was searching for a solution, but I haven't found any answer yet.
One solution would be to create a User and a UserData entity, and have a one to one relationship. But maybe there is a better solution

Zend Framework Doctrine create entity with ManyToMany

I'm using Zend Framework 2 with Doctrine.
I have two entities with ManyToMany relations, Portfolio and Tag.
When I'm editing Portfolio, I use select2 and I have possibility to not only select existing Tags, but also create new Tag from text input.
Can someone give me advice how to implement creation of new Tag? Seems like this case (zf2, doctrine, select2) is typical. Is there built-in methods to create new entities?
Logically Many to Many relationships should be resolved into One to Many with a new table.
if you can post your table schema I will create you the complete model/entity.

Doctrine many-to-many join without association

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.

PropelORM and database structure

I need to decide which approach to choose for my MySQL DB.
Example:
PHOTO ALBUM
User - can own photoalbum
Group - can own photoalbum
(maybe more entities could own photoalbum)
Now how to represent this in DB so it will:
Work nicely with Propel (join selects etc.)
I believe one approach is called polymorphic associations. But it has its own problem and I cannot find any resource talking about polymorphic associations with propel.
Second approach would be to represent everything separated. Meaning group_photoalbum user_photoalbum. It would be cleaner in MySQL and there will be no problem with Propel, but it would double most of the code and therefore any changes will be done twice.
Can Propel work with polymorphic associations? (any source)
Is there any other approach I don't know about?
Which would you choose?
Propel inheritance. Should have read the docs whole.
propel inheritance
Propel does not support polymorphic relationships.
You are best off using another ORM, if possible.
I mean, who uses XML 2018.
#Turnadiev Nursultan, he asked whether they support the relationship,
not if you can hack your way(which is a hack).

Best Way to handle Relational Data in CodeIgniter?

When creating a CodeIgniter project, what is the best way to handle relations between models? Should models contain other models that they are related to, should this be handled in the controller, or is there some other way to handle these scenarios? I'm thinking about one-to-one, one-to-many, or many-to-many relationships.
example: let's say I have a blog post, which has a many-to-many with tags, and a one-to-many with comments. What would be best practices for getting the tags and comments when getting blog posts?
Good question but there's no easy answer.
One project of mine uses a lot of database joins in its queries. So the correspondence is more one controller to one model, and that model then calls on a bunch of different tables.

Categories