concern about relation names

2 views
Skip to first unread message

Abraham

unread,
Aug 7, 2010, 11:20:11 PM8/7/10
to mysql-workbench-doctrine-plugin
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!

Johannes Mueller

unread,
Aug 8, 2010, 2:30:19 AM8/8/10
to mysql-workbench-doctrine-plugin
Hi Abraham,

My willing to fix all of the remaining issues is very small. As most
of these issues are related to special cases, where different things
come together. Because of their speciality they get hard to fix, need
plenty of time, interfere with doctrine manual or break backwards
compatibility.

When I change this to your preferred solution there will be many of
people that will have to deal with php code like this:

$item = new Item();
$item->addCategoryRelation(new Category());

This is fairly uncool. As it makes more sense to use it like it's
implemented:

$item = new Item();
$item->addCategory(new Category());

I hope you will a gree that you should focus on the programming
language rather than on your database model. It's "easy" to understand
database models by using graphical editors, but it's hard to follow
your programme, when you use uncommon naming conventions. You should
also consider, that other people may have to read your database in
phpMyAdmin and they might overlook the relation if you use uncommon
naming conventions.

Cheers
Johannes

PS: I plan to migrate the plugin from Lua to PHP and to discard the
MySQL workbench integration as plugin. It's to hard to maintain.

Abraham

unread,
Aug 9, 2010, 3:08:43 PM8/9/10
to mysql-workbench-doctrine-plugin
Thanks for your answer, i will name my foreign keys with the format
<foreignTable>_<foreignField> then.

Good luck moving the plugin to PHP.
Reply all
Reply to author
Forward
0 new messages