Hi all,
I have recently stumbled on a trouble related to the way you name
relations. For example, having three tables: Container, Category and
Item so that items belong to a category and are inside an arbitrary
container
(diagram image here:
http://imagepaste.nullnetwork.net/viewimage.php?id=1206),
the plugin will output this:
---
detect_relations: true
options:
collate: latin1_swedish_ci
charset: latin1
type: InnoDB
Container:
columns:
id:
type: integer(4)
primary: true
notnull: true
destination:
type: string(45)
notnull: true
arrival_date:
type: date
notnull: true
Category:
columns:
id:
type: integer(4)
primary: true
notnull: true
name:
type: string(45)
notnull: true
Item:
columns:
id:
type: integer(4)
primary: true
notnull: true
container:
type: integer(4)
primary: true
notnull: true
category:
type: integer(4)
notnull: true
name:
type: string(45)
notnull: true
description:
type: string(100)
notnull: true
relations:
container:
class: Container
local: container
foreign: id
foreignAlias: Items
category:
class: Category
local: category
foreign: id
foreignAlias: Items
***
As you can see, I have set the name of foreign keys in table Item
exactly the same as foreign tables i.e. 'container' and 'category', I
find this convenient because later I don't have to modify generator in
symfony 1.4 to rename those fields.
However, since relations have the same name that local foreign keys,
when I try to save a new item, the process crashes due to a null value
passed for category field. I think is a weird error, but happens.
Hence, i think that better naming for relations would be *_relation
e.g.
...
relations:
container_relation:
class: Container
local: container
foreign: id
foreignAlias: Items
category_relation:
class: Category
local: category
foreign: id
foreignAlias: Items
What do you think? I know is better to set foreign key names like
'<ForeignTable>_<ForeignField>' but as i said, i find convenient to
set barely the name of the foreign table, is this wrong?
Also, that way you will be sure relation names will be always distinct
to any field of the same table.
Thanks in advance!