Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:20:31+00:00 2026-06-17T05:20:31+00:00

So, we have two entities. One with repository and another is not. When we

  • 0

So, we have two entities. One with repository and another is not. When we trying to get the data from another table we will get the ArrayCollection data. Question is how to call this entity repository methods? Is it real?

Example:

    $system = $this
            ->getDoctrine()
            ->getEntityManager()
            ->getRepository('SomeBundle:FirstEntity')
            ->findOneByColumnID($id);

    $den = $system->getDataFromSecondTable(); // ArrayCollection of SecondEntity

And then i want to use some kind of:

    $den[0]->functionFromSecondEntityRepository();

So, method “functionFromSecondEntityRepository” is in Repository of class SecondEntity and i can’t call it – error on undefined method call “functionFromSecondEntityRepository”.

So how can i do it in right way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:20:33+00:00Added an answer on June 17, 2026 at 5:20 am

    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();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two entities one called User and another called Membership which has a
I have two entities, a User and Role with a one-to-many relationship from user
I have two entities in core data with one to many relationship between them
I have two entities Room.php /** * @ORM\Table(name=room) * @ORM\Entity(repositoryClass=Ahsio\StackBundle\Repository\RoomRepository) */ class Room {
I have two entities referenced one to many. When entity framework created the table
I have two entities one is Event and another is User. User can like
I have two entities with a Unidirectional Many-to-One mapping. Here's Product : use Doctrine\Common\Collections\ArrayCollection;
Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's
i have two Entities, Parent and Child, that are linked through a bidirectional one-to-many
This is situation I have: I have two entities with one-to-many relationship mapped like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.