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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:38:21+00:00 2026-06-12T13:38:21+00:00

Based on this post: How to set the id of a foreign key id

  • 0

Based on this post: How to set the id of a foreign key id #sf2 #doctrine2

In the previous post I found this solution

class Item
{
/**
 * @ORM\ManyToOne(targetEntity="MyBundle\Entity\ItemType", inversedBy="itemTypes")
 * @ORM\JoinColumn(name="type_id", referencedColumnName="id")
 */
protected $item_type;
/**
 * 
 * @var string $item_type_id
 * @ORM\Column(type="integer")
 */
protected $item_type_id;
}
.... Setter & Getter
}

Which allows me to do something like that

$item = new Item();
$item->setItemTypeId(2); // Assuming that the ItemType with id 2 exists.

But from the last update of doctrine2.3 it’s not working anymore.

when I persist the item(so creating the INSERT SQL query), it does not set the item_type_id field. only all other fields.

Any idea how to set manually the item_type_id without retrieve the ItemType just before setting it ? it’s quite over use of queries !?

$item = new Item();
$itemType = $this->entity_manager->getRepository('Acme\MyBundle:ItemType')->find(2);
$item->setItemType($itemType); // Assuming that the ItemType with id 2 exists.
  • 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-12T13:38:22+00:00Added an answer on June 12, 2026 at 1:38 pm

    I’ve found the solution of this problem.

    As we are working with an ORM, we usually do not use the identifier of an element and just work with the object itself.

    But sometimes it is convenient to use the object ids instead of the objects, for example when we store an identifier in the session (ex: user_id, site_id, current_process_id,…).

    In these circumstances, we should use Proxies, I’ll refer to the Doctrine documentation for more information:
    http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/advanced-configuration.html#reference-proxies

    In this example we would then have something like this:

    $itemTypeId = 2; // i.e. a valid identifier for ItemType
    $itemType = $em->getReference('MyProject\Model\ItemType', $itemTypeId);
    $item->setItemType($itemType);
    

    Hope it will help others.

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

Sidebar

Related Questions

I looked at previous post based on this but they do not relate. I
This is based on generating a second x-axis, as described in this previous post:
Again, I was creating buttons dynamically based on this post and now I need
Based on this SO post , and this example , I expect that, when
I've been reading this post Creating a login form in CodeIgniter based on Ion
This blog post of December 2008 says that rubygems is broken on Debian-based systems.
class Followup < ActiveRecord::Base belongs_to :post belongs_to :comment end This model needs to only
I've read in this post: The joy of Rx: The event-based asynchronous pattern vs
I'm using a 'rolling' cURL multi implementation (like this SO post , based on
(A working solution, based on the responses, is provided at the end of 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.