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 8566973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:46:41+00:00 2026-06-11T17:46:41+00:00

A Symfony2 application has a Job entity which has a tasks property, a collection

  • 0

A Symfony2 application has a Job entity which has a tasks property, a collection of Task entities.

Job->getTasks() is used to iterate over a given job’s collection of tasks. The Task entities encapsulated in the tasks property are lazy-loaded by Doctrine. I’m guessing they’re loaded at the point getTasks() is called.

With extra details removed, the Job entity looks something like this:

<?php

class Job
{        
    /**
     * @var \Doctrine\Common\Collections\Collection
     * @ORM\OneToMany(targetEntity="Example\Bundle\Entity\Task\Task", mappedBy="job")
     */
    private $tasks;

    public function __construct()
    {
        $this->tasks = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getTasks()
    {        
        return $this->tasks;
    }
}

I often need to access only a subset of all tasks (maybe 10 out of 1000) for a job and currently do so by iterating over getTasks() and picking out those with relevant ids.

For large collections of tasks (thousands, tens of thousands) it can take a long time for the tasks collection to be loaded from the database.

I’d like to reduce the time required to gain access to a subset of tasks. I can do so by using a custom entity repository to retrieve Task entities by id and job.

I’d like to know if a in-built feature of Symfony2 and/or Doctrine2 already exists for doing this.

My thinking is that an entity with a related collection of entities is a common situation (blog post and comments, for example) and that there may be some pagination-related concept at the entity level for retrieving only a subset of related entities.

Is there an in-built Symfony2 feature for what I need?

Update1:

I’d ideally like to be able to still iterate over Job->getTasks() knowing that it will return only a subset of tasks that I have somehow specified.

  • 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-11T17:46:42+00:00Added an answer on June 11, 2026 at 5:46 pm

    I think you are looking for Extra Lazy Association.

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

Sidebar

Related Questions

In my Symfony2 application, there are two entities: Address and Town. The Address entity
I work on a Symfony web application which has a standard login form. To
In a multi tenant web application should Symfony2 ACL framework be used for checking
I have multiple symfony2 applications which share common entities, but use different database settings.
In my server, a Symfony2 application is running. Moreover, the server has a folder
I have a entity called Container in a Symfony application, which I have included
I have a legacy application that I would like to move over to Symfony2.
I write an application with Symfony 2. I have a form which has a
I'm using symfony for one of my projects. The application has already developed and
My Symfony2 application replaces my PHPSESSID cookie when it logs me in. Is this

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.