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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:10:37+00:00 2026-06-13T11:10:37+00:00

I have a very basic schema like this: Comments.yml: manyToOne: pages: targetEntity: Pages inversedBy:

  • 0

I have a very basic schema like this:

Comments.yml:

manyToOne:
  pages:
    targetEntity: Pages
    inversedBy: comments
    joinColumn:
      name: page_id
      referencedColumnName: idx

... other things ...

Pages.yml:

oneToMany:
  comments:
    targetEntity: Comments
    mappedBy: pages
    cascade: ["persist"] // i added this later but has no effect for both persist and merge.
    orderBy:
      idx: desc

... other things ...

Now, everything is working just fine. I can get Pages from Comments and reverse. The problem is, when i try to insert a new row to the database, it says page_id is null.

Example:

$comment = new Comments();
$comment->setPageId(2); // it is "2"
$comment->setText($textData);

$this->_em->persist($comment);
$this->_em->flush($comment);

Now the result is false. It throws an exception and says SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "page_id" violates not-null constraint.

Well, if i remove the oneToMany and ManyToOne relations, it works! If i use them it says it is null even if i give it…

Where is my mistake? Any help or idea is appreciated!

EDIT:

I found this method: getReference()

$item = $em->getReference('MyProject\Model\Item', $itemId);
$cart->setPage($item);

Now it is working but i do not know if this is the correct way. Please inlight me.

Basically, i want to add a comment without modifying (not remove nor update) the page table. But, i want to fetch them together as ManyToOne and OneToMany.

  • 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-13T11:10:38+00:00Added an answer on June 13, 2026 at 11:10 am

    When You want to add a page to the Comments entity You should call a method like $comment->setPage($page) this method is automatically generated if you use the php app/console doctrine:generate:entities command line. The $page object should be the $page object loaded from the database. e.g.

    $page = $this->getDoctrine()->getRepository('Pages')->findOneBy(array('id' => $pageId));
    
    $comment = new Comments();
    $comment->setPage($page);
    $comment->setText($textData);
    
    $this->_em->persist($comment);
    $this->_em->flush();
    

    If this doesn’t help You, please post your code from your controller and the pages and comments entity.

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

Sidebar

Related Questions

I've got a very basic database schema and have created a dbml from it.
I'm a total Ruby/Rails/AR noob. I have a very basic sort of database schema
I have a very basic mysql table called memberships, that tracks which people belong
I have a very basic API in my app which also has an index
I have a very basic windows forms app, working in C#, and I was
I have a very basic app with two ignition-remoteimageviews (RIV) in them. The app
I have some very basic semaphore code that works great on Linux, but cannot
I have a very basic doubt regarding the method that gets executed when app
I have a very basic knowledge of the web programming, and I couldn't figure
I have a very basic texture map problem in GL on iPhone, and I'm

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.