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

  • SEARCH
  • Home
  • 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 8175631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:50:46+00:00 2026-06-06T22:50:46+00:00

I have an table Article that is in relationship with Steps (OneToMany) and Steps

  • 0

I have an table Article that is in relationship with Steps (OneToMany) and Steps with Article ManyToOne.

I get Articles with:

$articles = $this->getDoctrine()
            ->getRepository("IftodiDesignBundle:Article")
            ->findAll();

And with foreach I want to show all Articles and Steps:

foreach($articles as $article)
    {
        $steps = $this->getDoctrine()
                ->getRepository("IftodiDesignBundle:Steps")
                ->createQueryBuilder('s')
                ->where('s.article = \''.$article.'\'')
                ->getQuery()
                ->execute();

        echo "<b>".$article->getTitle()."</b><br />";
        echo $article->getText()."<br />";
    }

I don’t know how to get data from table Steps usign the table Article and method getSteps() that is generated with Doctrine.

Please help me.


Thanks for the answer.

In table Article I have:

 /**
 * @ORM\OneToMany(targetEntity="Steps", mappedBy="Steps",cascade={"persist"})
 * @ORM\JoinColumn(name="id", referencedColumnName="id_article")
 */
protected $steps;

In table Steps:

/**
 * @ORM\ManyToOne(targetEntity="Article", inversedBy="steps")
 * 
 */
protected $article;

When I do:

 $articles = $this->getDoctrine()
            ->getRepository("IftodiDesignBundle:Article")
            ->findAll();

If I do:

foreach($articles as $article)
    {
        $steps = $article->getSteps();

I recieve error:

 Notice: Undefined index: Steps in /var/www/design/vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1280

If I do that:

    $articles = $this->getDoctrine()
            ->getRepository("IftodiDesignBundle:Article")
            ->findAll();
    foreach($articles as $article)
    {
        //Queries to DB
         $steps = $this->getDoctrine()
            ->getRepository("IftodiDesignBundle:Steps")
            ->findBy(array(
                "article"    => $article->getId()
            ));
         $media = $this->getDoctrine()
                 ->getRepository("IftodiDesignBundle:Media")
                 ->findBy(array(
                     "step" => $steps[0]->getId()
                 ));

I can obtain data that I need, but here are more interrogation to DB.

  • 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-06T22:50:47+00:00Added an answer on June 6, 2026 at 10:50 pm

    Delete @ORM\JoinColumn(name="id", referencedColumnName="id_article") from your annotation – doctrine will map your association into MySQL with sensible defaults.

    Once you have deleted, regenerate your SQL: doctrine:schema:update --force

    Furthermore if you are looping over your articles to get your steps, you are better off writing a custom method in your repository otherwise each time you call ->getSteps() Doctrine will make an SQL call (imagine looping over 100 articles – you would end up making 101 calls to the database!)

    To avoid this you can put a method like so in your repository

    public function all()
    {
        $queryBuilder = $this->getEntityManager()->createQueryBuilder();
    
        $queryBuilder
            ->select('Article', 'Steps')
            ->from('IftodiDesignBundle:Article')
            ->leftJoin('Article.steps', 'Steps')
        ;
    
        // consider using ->getArrayResult() to use less memory
        return $queryBuilder->getQuery()->getResult(); 
    }
    

    I put together a few more best practices in a blog post

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table, e.g. pricerules, that have stored special prices by article for
I have a table articles that has a column company which has list of
I have a primary table for Articles that is linked by a join table
I have a simple cakephp app with table articles that has a cat_id column
I have a table that contains articles posted by users. The structure of the
Lets say I have a table in MySQL called articles, that has a column
I've got two tables (articles and tags) that have a one-to-many relationship. I remember
I have a table with products. When I get information from that table, I
I have Table: ARTICLES ID | CONTENT --------------- 1 | the quick 2 |
I have a table 'articles' : id / uid / last_update / content. I

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.