Create Doctrine DQL query by instance of and select child column - symfony

I'm trying to make a query to fetch a discriminator column.
Here is what I have to fetch all links related to an Entity class:
SELECT transaction.id FROM Entity transaction
INNER JOIN transaction.links link WHERE (link INSTANCE OF Child)
So, the Entity class has an associates links method which is returning all Child entities related to it.
Now, I want to fetch a number column from link which is an instance of child class.
Something like: link.number
Is it possible to make Doctrine DQL for this? What I received from my DQL is this:
Class Child has no field or association named number

Related

How to get entity class from table name in Doctrine?

I am working on a Symfony + Doctrine based project. Is it possible to query an entity class using a given table name?
I know that it is no problem to ask Doctrine which table name belongs to a given entity class but I need this the other way (table name -> entity class, NOT entity class -> table name).
Asking Doctrine for all table names of all configured entities does not work in my case, since I need this feature within a bundle which is used in different projects and thus does not know all the project entities...

symfony create a table with attribute from multiple entities

I have different entities like:
Element, Status, Action, Contributor ...
And I need to create an entity, let say Synonym, which can be related to one of these previous entities
My entity Synonym, can be a synonym of the entity Element or Status or Action ...
I try to use a MappedSuperclass but I'm really lost.
I think this kind of relation is common and must be easy to create with doctrine but I can't find the good way.

Sort by entity's method with KNP pagination

I have entity with method getItemsAmount, that fetches all Item entities related to my parent entity, counts them and returns result as regular integer.
Then I create table for parent entity with "Items Amount" column.
Now when i try to configure KNP pagination to sort by "itemsAmount" property of parent entity, I do get exception:
There is no such field [itemsAmount] in the given Query component, aliased by [a]
Thats obvious - I do not have such a property, I calculate it with my Entity class after its fetched.
Is there possibility to make KNP pagination sort such things ?

Doctrine - Get entity and relationships in one query

Am I missing a point with Doctrine? It's been very useful for some scenarios, but for the basic scenario of retrieving an entity using an Id (say using find() or findOneBy()) why do you see a query being fired off for every relationship to populate the main entity's properties?
Surely with the mapping/annotations I've created, Doctrine should be capable of a few joins and one query, without having to write a DQL query for the retrieval of each entity.
Or, as I'm predicting, have I missed the point somewhere!
Just add the aliases of related entities to select part of your query.
Let’s say, you have Book related one-to-many to Cover, and you want so select some books with their covers.
With query builder, use:
->createQueryBuilder()
->select("book, cover")
->from("Book", "book")
->leftJoin("book.covers", "cover")
With query, use:
SELECT book, cover FROM Book book LEFT JOIN book.covers cover
As the result, you will receive collections of Book with prepopulated $covers collection.
Because the relationships are hydrated only when needed - by default Doctrine uses a lazy-loading strategy.
If you already know that you will access the related entities, you should build a DQL query that retrieves the record AND the related entities.

asp.net MVC fetching data with table relations

I have created my Database which has:
Artist, tracks and TracksPerArtists
I can do sql queries through the entity model. For example when I make:
database.TRACK.ToList()
I get the list of track to be shown on index view for example. But my foreign keys come empty. While there is an artist and a track, and the correct row for ArtistsPerTrack, this item in my track.ToList() collection is empty.
Is there a different way to fetch those data?
I came from cakePHP framework in which you can define the Model.recursive property to declare the depth of the relations you want to fetch.
Is there anything similar here?
There is something similar.
If "database" is DataContext and Artist and Tracks have many to many relationship in database, you can fetch related entities using Include clause:
database.TRACK.Include("Artists").ToList()
where "Artists" is the name of property on Track entity.

Resources