[eluser]TheJonas[/eluser]
Hi everybody,
I'm having a pretty tough time getting a 1:n association with Doctrine to work.
Basically, there is a Relationship and a RelationshipType with each Relationship having one RelationshipType and each RelationshipType having pot. many Relationships.
My Relationship.php (model) looks like this:
Code:
/** @Entity
* @Table(name="relationship")
*
*/
class Relationship extends CI_Model
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @ManyToOne(targetEntity="RelationshipType", inversedBy="relationships")
* @JoinColumn(name="fk_relationship_type_id", referencedColumnName="id")
*/
private $relationshipType;
}
And my RelationshipType.php looks like this:
Code:
/** @Entity
* @Table(name="relationship_type")
*
*/
class RelationshipType extends CI_Model
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @oneToMany(targetEntity="Relationship", mappedBy="relationshipType")
*/
private $relationships;
/**
* @Column(name="relationship_name", length=255)
*/
private $relationshipName;
public function __construct()
{
$this->relationships = new \Doctrine\Common\Collections\ArrayCollection();
}
My tables look like this:
Code:
--
-- Table structure for table `relationship`
--
CREATE TABLE IF NOT EXISTS `relationship` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_from_person_id` int(11) NOT NULL,
`fk_to_person_id` int(11) NOT NULL,
`fk_relationship_type_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `relationship`
--
INSERT INTO `relationship` (`id`, `fk_from_person_id`, `fk_to_person_id`, `fk_relationship_type_id`) VALUES
(1, 1, 2, 1),
(2, 1, 3, 1);
-- --------------------------------------------------------
--
-- Table structure for table `relationship_type`
--
CREATE TABLE IF NOT EXISTS `relationship_type` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`relationship_name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `relationship_type`
--
INSERT INTO `relationship_type` (`id`, `relationship_name`) VALUES
(1, 'friendship');
The problem definitely is the 1:n association as if I comment out the field then everythign works fine, if I run the code as posted here I get the following error:
Quote:A PHP Error was encountered
Severity: Warning
Message: file_put_contents(application//models/proxies\RelationshipTypeProxy.php) [function.file-put-contents]: failed to open stream: No such file or directory
Filename: Proxy/ProxyFactory.php
Line Number: 154
A PHP Error was encountered
Severity: Warning
Message: require(application//models/proxies\RelationshipTypeProxy.php) [function.require]: failed to open stream: No such file or directory
Filename: Proxy/ProxyFactory.php
Line Number: 85
Fatal error: require() [function.require]: Failed opening required 'application//models/proxies\RelationshipTypeProxy.php' (include_path='.;C:\Server\xampp\php\PEAR') in C:\Server\xampp\htdocs\CI\application\libraries\Doctrine\ORM\Proxy\ProxyFactory.php on line 85
Can anybody point me into the direction of my mistake? I've been reading the Doctrine docs but somehow I can't seem to find the problem :-(
Thank you very much in advance!