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.