OK, if anyone can help me with this that would be great, because it appears to be intractable.
I have 2 entities set up in a new zf-boilerplate project as below. I am trying to follow the tutorial on Zendcasts.com – One-to-Many with Doctrine 2, but can’t get doctrine to recognise the associations I have mapped. If I run orm:schema-tool:create --dump-sql, it dumps the generated Sql, but NOT the ALTER TABLE statements at the end which should would create the Foreign Key Mapping, I can’t get that to work properly.
I’ve tried everything I can think of, the JOIN statement I need to run obviously doesn’t work either, but I figure if I can just get Doctrine to recognise the ALTER statement I can carry it from there.
Any ideas would be great, let me know if you need more info. I thought at first maybe the .ini file might be set up wrong, but I think this is more something to do with the relationship annotation?
Library/Photo/Entity/Gallery.php
<?php
namespace Photo\Entity;
/**
* @Entity(repositoryClass="Photo\Entity\Repository\MyGallery")
* @Table(name="gallery")
*/
class Gallery {
/**
* @Id @GeneratedValue
* @Column(type="smallint",nullable=false)
* @var integer
* @OneToMany(targetEntity="Photo", mappedBy="galleryID")
*/
protected $id;
/**
* @Column(type="string", length=200)
* @var string
*/
protected $gallery;
Library/Photo/Entity/Photo.php
<?php
namespace Photo\Entity;
/**
* @Entity(repositoryClass="Photo\Entity\Repository\MyPhoto")
* @Table(name="photo")
*/
class Photo {
/**
* @Id @GeneratedValue
* @Column(type="smallint",nullable=false)
* @var integer
*/
protected $id;
/**
* @Column(type="smallint",nullable=false)
* @var integer
* @ManyToOne(targetEntity="Gallery")
* @JoinColumns({
* @JoinColumn(name="gallery_id", referencedColumnName="id")
* })
*/
protected $galleryID;
Hmm… I see.. Check you column names,
gallery_idvsgalleryIDlooks suspicious.If it is
gallery_id, then you have to change the$galleryIDannotation to@Column(type="smallint", nullable=false, name="gallery_id")Generally, everywhere in the object model you should use the object field names, for example
mappedBy="galleryID", but the column itself should be mapped with the appropriate DB name, like I mentioned@Column(name="gallery_id"), or for example@JoinColumns({@JoinColumn(name="gallery_id" referencedColumnName="id")})