You didnt provide too many details so I will make some example up here.
Let's say you have an Entity FriendsList
and a One-to-Many
relationship with Entity Friend
.
$List = $this->getDoctrine()
->getEntityManager()
->getRepository('SomeBundle:FriendsList')
->find($id);
// The list you pulled in by ID can now be used
$List->getId();
foreach($List->getFriends() as $Friend)
{
// Each friend will be output here, you have access
// to the Friend methods now for each.
$Friend->getId();
$Friend->getFirstName();
$Friend->getLastName();
$Friend->getDOB();
$Friend->getFavoriteColor();
}
By default when you create relationships a method to acquire the collection is created, in this example getFriends
which returns an array of Entities. After you generate the entities look at your Entity Model to see which methods are available. By default one is created for each property in your entity and additional ones for Collections.
SomeCool/Bundle/Entity/FriendsList
Somecool/Bundle/Entity/Friend
The following is what a one-to-many relationship would look like if you use YAML configuration.
SomeCool\Bundle\Entity\FriendsList:
type: entity
table: null
oneToMany:
friend:
targetEntity: Friend
mappedBy: friendslist
cascade: ["persist"]
SomeCool/Bundle/Entity/Friend
manytoOne:
friends:
targetEntity: FriendsList
mappedBy: friend
cascade: ["persist"]
Accessing a Repository
YAML Configuration (services.yml)
somebundle.bundle.model.friends:
class: SomeBundle/Bundle/Model/Friends
arguments: [@doctrine.orm.entity_manager]
On the Controller
$friendsModel = $this->get('somebundle.bundle.model.friends');
$Friends = $friendsModel->findByFirstName('Bobby');
foreach($Friends as $Friend)
{
$Friend->getLastName();
}