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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:21:47+00:00 2026-06-10T14:21:47+00:00

I have such relation: class TaskSet { /** * @var integer $id * *

  • 0

I have such relation:

class TaskSet
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @var \Doctrine\Common\Collections\ArrayCollection $tasks
     *
     * @ORM\OneToMany (targetEntity="Task", mappedBy="taskset", cascade={"ALL"})
     */
    private $tasks;

and

class Task
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var TaskSet $taskset
     *
     * @ORM\ManyToOne(targetEntity="TaskSet", inversedBy="tasks")
     */
    private $taskset;

generated SQL looks like:

CREATE TABLE task (
    id INT AUTO_INCREMENT NOT NULL, 
    taskset_id INT DEFAULT NULL, 
    INDEX IDX_527EDB255D67FAA4 (taskset_id), PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB;

CREATE TABLE task_set (
    id INT AUTO_INCREMENT NOT NULL, 
    PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB;   

ALTER TABLE task ADD CONSTRAINT FK_527EDB255D67FAA4 FOREIGN KEY (taskset_id) REFERENCES task_set (id)

Since now everything is well, I get one(testset) to many(test) bidirectional relation.

Unfortunately Doctrine2 chooses Task entity as owning side so this code is not persisting relation between entities:

$em = $this->getDoctrine()->getEntityManager();

$taskset = new TaskSet();
$taskset->setName('task 1');
$taskset->setDescription('desc 1');

$task =  new Task();
$task->setName('task 1');
$task->setClassName('class name 1');
$taskset->addTask($task);

$em->persist($taskset);
$em->flush();

output from code above is:

INSERT INTO `task_set` (`id`, `name`, `description`) VALUES (1, 'task 1', 'desc 1');
INSERT INTO `task` (`id`, `taskset_id`, `name`, `className`) VALUES (1, NULL, 'task 1', 'class name 1');

So finally questions:

  1. Is there a way to change owning side (of course I cannot revert relation)?
  2. How mark taskset_id as NOT NULL?
  • 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-10T14:21:49+00:00Added an answer on June 10, 2026 at 2:21 pm
    1. In class TaskSet, edit the addTask($task) function and add at the end:

      $task->setTaskset($this);

    2. As Carlos said in comment, my initial post doesn’t really answer the issue.
      You must use the nullable property on the JoinColumn definition:

      class Task
      {
      /**
      * @var integer $id
      *
      * @ORM\Column(name=”id”, type=”integer”)
      * @ORM\Id
      * @ORM\GeneratedValue(strategy=”AUTO”)
      */
      private $id;

      /**
       * @var TaskSet $taskset
       * 
       * @ORM\JoinColumn(nullable=false)
       * @ORM\ManyToOne(targetEntity="TaskSet", inversedBy="tasks")
       */
      private $taskset;
      

    Initial answer:

    1. Use a Validator, in your case the NotNull validator, on the $taskset property of your Task class.

    Example from Symfony2’s documentation:

    // src/Acme/BlogBundle/Entity/Author.php
    use Symfony\Component\Validator\Constraints as Assert;
    
    class Author
    {
        /**
         * @Assert\NotNull()
         */
        protected $firstName;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON feed data with lots of user relation in it such
I have such a for loop: for (var i = 0; i < documentsCount;
When you have a relation such as embeds_many :album_items which relates to the AlbumItem
I have such terrible models: class ParentalRelation < ActiveRecord::Base belongs_to :parent belongs_to :student belongs_to
i have a parent child table such that class Service( models.Model ): id =
I have such database structure: Class Company has a property CompanyInfoTableName Also I have
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
i have such code (copy paste from wiki). Its multiplication of those big numbers
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
i have such function to solve some logic riddle iloczyny is list with such

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.