I am in the process of creating a simple blog with Symfony / Doctrine 2 and running into a problem with the php app/console doctrine:migrations:diff
command.
Info:
- Postgresql
- Relevant tables: Post, Category, fos_user
- Post table should have 2 foreign keys: user_id and category_id
- Diff only generates one foreign key in post table
- If the manyToOne declaration for the user appears before the category id in post entity's doctrine config file, the post table gets a user_id foreign key but no category_id (when the diff runs)
- If you move the manyToOne declaration for the category entity above that of the user entity, the post table gets a category_id but no user_id.
I have tried the manyToOne declarations with and without the inversedBy part, the joinColumn part, etc. Below are my YML configs. With this config, a user_id foreign key will be created in the post table but no category id. (see bottom of the post config)
If anyone has any ideas I'd really appreciate it!
Post Entity config
Conduct\BlogBundle\Entity\Post:
type: entity
table: null
manyToOne:
user:
targetEntity: Acme\UserBundle\Entity\User
inversedBy: posts
joinColumn:
name: user_id
referencedColumnName: id
manyToOne:
category:
targetEntity: Conduct\BlogBundle\Entity\Category
inversedBy: posts
joinColumn:
name: category_id
referencedColumnName: id
lifecycleCallbacks: { }
Category Entity config
Conduct\BlogBundle\Entity\Category:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
title:
type: string
length: 255
oneToMany:
posts:
targetEntity: Conduct\BlogBundle\Entity\Post
mappedBy: category
lifecycleCallbacks: { }
User Entity config
Acme\UserBundle\Entity\User:
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
oneToMany:
posts:
targetEntity: Conduct\BlogBundle\Entity\Post
mappedBy: user
Category Entity Code
class Category
{
private $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
}
Post Entity Code
class Post
{
protected $category;
}