A
A
Alexander2016-11-25 00:39:46
symfony
Alexander, 2016-11-25 00:39:46

Will such a query affect performance?

There is a Book entity that has a ManyToOne relationship with the Location entity

class Book {
    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Location", inversedBy="bookFrom")
     * @ORM\JoinColumn(name="from_book", referencedColumnName="id")
     */
    private $fromBook;
}
class Location {
    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Book", mappedBy="fromBook")
     */
    private $bookFrom;
}

in the controller, I need to get the Book parameters
$from = $book->getFromBook();
this way I get all the related entity
further $from I pass it as a parameter to another repository to perform another search
QUESTION is the following: Will such a construction affect performance
or is it necessary like this
$from = $book->getFromBook() ->getAlias() ;
pull the value of an entity, not the entity itself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2016-11-25
@alexmixaylov

or is it necessary
pull out the value of the entity, and not the entity itself

If alias is not a field that is an Id (judging by your mapping, it is not), then you will still have the entire Book entity pulled out.
Just in case you do
You will not query the db.
You understand what's the matter. If you start dragging the values ​​of specific fields from the database instead of objects through the ORM, you may not need an ORM at all.
In general, it is likely that you are trying to save on matches. How many such requests will you make per page?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question