Hi,

give a try and change the referencedColumnName to id 

/**
 * @ORM\OneToOne(targetEntity="ItemPrice")
 * @ORM\JoinColumn(name="item_id", referencedColumnName="id", nullable=true)
 */
protected $price;
...
}



and change the *name of the id column to id* for both models.

The creation of the column item_id will be done by this mapping itself.

Actually there could be some name issue by your current mapping.

I hope this will be solution for this exception.

Greetings, Christian

Am Samstag, 15. November 2014 22:26:30 UTC+1 schrieb pmf:
>
> Hi,
>
> I want to specify relation between two entities Item and ItemPrice. Item 
> can have a price, but does not have to, so it should be something like left 
> join in sql. I used OneToOne relation, JoinColumn with nullable=true and I 
> am getting *EntityNotFoundException* exception. Here is my code:
>
> class Item
> {
>
> /**
>  * @ORM\Column(type="integer")
>  * @ORM\Id
>  * @ORM\GeneratedValue(strategy="IDENTITY")
>  */
> protected $item_id;
>
> /**
>  * @ORM\Column(type="string")
>  */
> protected $name;
>
> /**
>  * @ORM\Column(type="string")
>  */
> protected $image_file;
>
> /**
>  * @ORM\OneToOne(targetEntity="ItemPrice")
>  * @ORM\JoinColumn(name="item_id", referencedColumnName="item_id", 
> nullable=true)
>  */
> protected $price;
> ...
> }
>
>
> class ItemPrice
> {
>
> /**
>  * @ORM\Column(type="integer")
>  * @ORM\Id
>  */
> protected $item_id;
>
> /**
>  * @ORM\Column(type="integer")
>  */
> protected $gold;
>
> /**
>  * @ORM\Column(type="integer")
>  */
> protected $silver;
>
> /**
>  * @ORM\Column(type="integer")
>  */
> protected $bronze;
> ...
> }
>
>
> Tables:
>
> CREATE TABLE `item` (
> `item_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
> `name` varchar(150) NOT NULL,
> `image_file` varchar(100) DEFAULT NULL,
> PRIMARY KEY (`item_id`),
> UNIQUE KEY `uk_item_name` (`name`));
>
> CREATE TABLE `item_price` (
> `item_id` int(11) NOT NULL,
> `gold` int(11) NOT NULL DEFAULT '0',
> `silver` int(11) NOT NULL DEFAULT '0',
> `bronze` int(11) NOT NULL DEFAULT '0',
> PRIMARY KEY (`item_id`));
>
>
> I think what I did is called unidirectional OneToOne: 
> http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#one-to-one-unidirectional
>  Which 
> in my opinion is exactly what I need.
>
> Exception appears when I want to fetch object which does not have its 
> price in item_price table.
>
> What am I doing wrong?
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to