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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:24:16+00:00 2026-05-28T21:24:16+00:00

$test have other $type and price for it different. In cart can be $test

  • 0

$test have other $type and price for it different. In cart can be $test with same id, but other $type and that’s a different product (object).

Example:

    foreach ($cart as $order) {
        $test = $em->getRepository('OrfosCoreBundle:Test')->find($order['test_id']);
        $test->setType($order['test_type']);
        $tests[] = $test;
        $test = null;
    }

and in $tests array doctrine return the same object if $order['test_id'] == previous $order['test_id']

array
  0 => 
    object(Orfos\CoreBundle\Entity\Test)[105]
  1 => 
    object(Orfos\CoreBundle\Entity\Test)[105]

How I can get new object?

  • 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-05-28T21:24:16+00:00Added an answer on May 28, 2026 at 9:24 pm

    Entities are uniquely identified by an identifier (primary key, in other terms).
    Two entities with same identifier are the same object when you’re thinking in ORMs.
    So what you will have there is just an array full of references to the same object (Doctrine\ORM\EntityRepository#find will get also the same instance if one is registered!)
    What you should probably do there is creating new instances of your Test entity, assign all fields values to them by calling all the different setters you have defined, persist them via Doctrine\ORM\EntityManager#persist() and populate the array. Flushing the EntityManager via Doctrine\ORM\EntityManager#flush() will save all elements in the array into db on separate records.

    If you want to clone the object instead, then you’ll have to work with Doctrine\ORM\EntityManager#detach(), which I wouldn’t suggest you if you are just starting with the ORM. In this case, consider reading my solution posted on the Doctrine mailing list about Cloning Persisted Entities

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

Sidebar

Related Questions

I have this small app that loads plugin type components that other users can
I have an object that takes in a parameter of the same type in
I have a test that is successful (among other things) if a certain callback
I have two Perl files: action.pl and the other is test.pl action.pl has a
I have a test file that contains tests taking quite a lot of time
I have a test winforms app with ThreadExceptionHandler that displays a message box when
I have a test file that has many lines, each line looks something like:
I have just setup my website locally so I can test my pages more
I have read other related posts, but am still not quite sure how, or
I have a base class that represents a database test in TestNG, and 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.