I have two tables A (Utenti) e B (Dispositivi); on B there is a foreign key to A (one Utente->many Dispositivi). I used symfony admin generator. Can I generate a link for each Utente that list me all the related Dispositivi in the Dispositivi view. Is it possible this?
schema.yml
Dispositivi:
connection: doctrine
tableName: dispositivi
columns:
id_dispositivo:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
device_id:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
tipo:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
utente_fk:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Utenti:
local: utente_fk
foreign: id_utente
type: one
Utenti:
connection: doctrine
tableName: utenti
columns:
id_utente:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
username:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
password:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
tipo:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Dispositivi:
local: id_utente
foreign: utente_fk
type: many
Servizi:
local: id_utente
foreign: utente_fk
type: many
Here is a good reference for doctrine code:
http://redotheweb.com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/
(especially if fou are used to propel.)
First, add a partial in the generator.yml file.
Then do something like this:
<?php
$dispositivis = $utente->Dispositivis;
?>
<?php foreach ($dispositivis as $d): ?>
<?php echo link_to($d->getTipo(), 'module_name/action_name?id='. $d->getIdDispositivo()) ?><br />
<?php endforeach ?>
Related
I'm trying to build this query:
SELECT
re . *, t.tipo, m.patente, o.nombre, de.revisado
FROM
sdriving_registros_emisores re
LEFT JOIN
sdriving_turno t ON re.idturno = t.idturno
LEFT JOIN
sdriving_maquina_emisor me ON me.idmaquinaemisor = re.maquinaemisorid
LEFT JOIN
sdriving_maquina m ON me.idmaquina = m.idmaquina
LEFT JOIN
sdriving_operador o ON re.idoperador = o.idoperador
LEFT JOIN
sdriving_detalle_emisores de ON de.idregistros = re.idregistros
WHERE
o.idempresa = 1
using Doctrine DQL. This is the code I made:
Doctrine_Core::getTable('SdrivingRegistrosEmisores')
->createQuery('re')
->leftJoin('re.SdrivingTurno t')
->leftJoin('re.SdrivingMaquinaEmisor me')
->leftJoin('me.SdrivingMaquina m')
->leftJoin('re.SdrivingOperador o')
->leftJoin('re.SdrivingDetalleEmisores de')
->execute();
But if I add where('o.idempresa', $id_empresa) I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'o.idempresa' in 'where clause'
What's the proper way to do this? What I miss?
EDIT Added the schema.yml file:
SdrivingDetalleEmisores:
connection: doctrine
tableName: sdriving_detalle_emisores
actAs: [Timestampable]
columns:
iddetalle_emisores:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
idregistros:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
fecha_registro:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
dertalle_mensaje:
type: string()
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
estado:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
revisado:
type: integer(1)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
modo:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
remitente:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SdrivingRegistrosEmisores:
local: idregistros
foreign: idregistros
type: one
SdrivingEmisor:
connection: doctrine
tableName: sdriving_emisor
actAs: [Timestampable]
columns:
idemisor:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
idempresa:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
numero:
type: string(50)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SdrivingEmpresa:
local: idempresa
foreign: idempresa
type: one
SdrivingMaquinaEmisor:
local: idemisor
foreign: idemisor
type: many
SdrivingEmpresa:
connection: doctrine
tableName: sdriving_empresa
columns:
idempresa:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
idlogotipo:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
nombre_empresa:
type: string(250)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
ruta_emp:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SdrivingLogotipo:
local: idlogotipo
foreign: idlogotipo
type: one
SdrivingEmisor:
local: idempresa
foreign: idempresa
type: many
SdrivingMaquina:
local: idempresa
foreign: idempresa
type: many
SdrivingOperador:
local: idempresa
foreign: idempresa
type: many
SdrivingTurno:
local: idempresa
foreign: idempresa
type: many
SfGuardUserProfile:
local: idempresa
foreign: idempresa
type: many
SdrivingLogotipo:
connection: doctrine
tableName: sdriving_logotipo
columns:
idlogotipo:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
archivo:
type: string(250)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
SdrivingEmpresa:
local: idlogotipo
foreign: idlogotipo
type: many
SdrivingMaquina:
connection: doctrine
tableName: sdriving_maquina
actAs: [Timestampable]
columns:
idmaquina: { type: integer(8), fixed: false, unsigned: false, primary: true, autoincrement: true }
idempresa: { type: integer(4), fixed: false, unsigned: true, primary: true, autoincrement: false }
patente: { type: string(12), fixed: false, unsigned: false, primary: false, notnull: true, autoincrement: false }
relations:
Empresa:
local: idempresa
class: SdrivingEmpresa
type: one
foreignType: one
foreignAlias: MaquinaEmpresa
onDelete: CASCADE
onUpdate: CASCADE
Emisor:
local: idmaquina
class: SdrivingMaquinaEmisor
type: many
foreignType: many
foreignAlias: MaquinaEmisor
onDelete: CASCADE
onUpdate: CASCADE
SdrivingMaquinaEmisor:
connection: doctrine
tableName: sdriving_maquina_emisor
actAs: [Timestampable]
columns:
idmaquinaemisor:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
idmaquina:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
idemisor:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
relations:
SdrivingEmisor:
local: idemisor
foreign: idemisor
type: one
SdrivingMaquina:
local: idmaquina
foreign: idmaquina
type: one
SdrivingRegistrosEmisores:
local: idmaquinaemisor
foreign: maquinaemisorid
type: many
SdrivingOperador:
connection: doctrine
tableName: sdriving_operador
actAs: [Timestampable]
columns:
idoperador:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
idempresa:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
nombre:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
rut:
type: string(12)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SdrivingEmpresa:
local: idempresa
foreign: idempresa
type: one
SdrivingRegistrosEmisores:
local: idoperador
foreign: idoperador
type: many
SdrivingRegistrosEmisores:
connection: doctrine
tableName: sdriving_registros_emisores
actAs: [Timestampable]
columns:
idregistros:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
maquinaemisorid:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
idoperador:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
idturno:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
relations:
SdrivingTurno:
local: idturno
foreign: idturno
type: one
SdrivingOperador:
local: idoperador
foreign: idoperador
type: one
SdrivingMaquinaEmisor:
local: maquinaemisorid
foreign: idmaquinaemisor
type: one
SdrivingDetalleEmisores:
local: idregistros
foreign: idregistros
type: many
SdrivingTurno:
connection: doctrine
tableName: sdriving_turno
actAs: [Timestampable]
columns:
idturno:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
idempresa:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
tipo:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SdrivingEmpresa:
local: idempresa
foreign: idempresa
type: one
SdrivingRegistrosEmisores:
local: idturno
foreign: idturno
type: many
SfGuardUserProfile:
connection: doctrine
tableName: sf_guard_user_profile
columns:
id: { type: integer(8), primary: true }
user_id: { type: integer(8), primary: false }
idempresa: { type: integer(4), primary: false }
relations:
User:
local: user_id
class: sfGuardUser
type: one
foreignType: one
foreignAlias: SfGuardUserProfile
onDelete: CASCADE
onUpdate: CASCADE
I need to modify Admin Generator's Doctrine Form which is included by:
$this->embedRelation('MyRelation');
The default layout looks like this:
The goal - every Item of Select should be displayed as text in separate row, plus Price and Quantity:
schema.yml
Game:
actAs:
Timestampable: ~
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
game_name: { type: string(100), notnull: true }
indexes:
it:
fields: game_name
type: unique
Campaign:
actAs:
Timestampable: ~
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
name: { type: string(100), notnull: true }
is_active: { type: boolean, notnull: true, default: 0 }
start: { type: datetime, notnull: true }
end: { type: datetime, notnull: true }
relations:
CampaignMatrix: { onDelete: CASCADE, local: id, foreign: campaign_id, foreignAlias: CampaignMatrixCampaign }
CampaignGames:
actAs:
Timestampable: ~
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
campaign_id: { type: integer(4), notnull: true, unsigned: true }
game_id: { type: integer(4), notnull: true, unsigned: true }
indexes:
tc:
fields: [campaign_id, game_id]
type: unique
relations:
Campaign: { onDelete: CASCADE, local: campaign_id, foreign: id, foreignAlias: CampaignCampaignGames }
Game: { onDelete: CASCADE, local: game_id, foreign: id, foreignAlias: GameCampaignGames }
CampaignMatrix:
actAs:
Timestampable: ~
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
item_id: { type: integer(4), notnull: true, unsigned: true }
campaign_id: { type: integer(4), notnull: true, unsigned: true }
price_id: { type: integer(4), notnull: true, unsigned: true }
quantity: { type: integer(4), notnull: true, unsigned: true }
relations:
Item: { onDelete: CASCADE, local: item_id, foreign: id, foreignAlias: ItemCampaignMatrix }
Campaign: { onDelete: CASCADE, local: campaign_id, foreign: id, foreignAlias: CampaignCampaignMatrix }
Price: { onDelete: CASCADE, local: price_id, foreign: id, foreignAlias: PriceItems }
Price:
columns:
id: { type: integer(4), unsigned: true }
currency_code: { type: string(3), notnull: true }
price: { type: float, notnull: true }
indexes:
tc:
fields: [id, currency_code]
type: unique
Item:
actAs:
Timestampable: ~
I18n:
fields: [name, description, image]
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
game_id: { type: integer(4), notnull: true, unsigned: true }
product_id: { type: string(100), notnull: true }
price_id: { type: integer(4), notnull: true, unsigned: true }
quantity: { type: integer(4), notnull: true, unsigned: true }
name: { type: string(100), notnull: true }
description: { type: string(255), notnull: true }
image: { type: string(255), notnull: true }
indexes:
it:
fields: item_type
relations:
Game: { onDelete: CASCADE, local: game_id, foreign: id, foreignAlias: GameItems }
Price: { onDelete: CASCADE, local: price_id, foreign: id, foreignAlias: PriceItems }
This is how I do it:
$list = MainItemTable::getInstance()->findByGameId($gameId);
$CampaignMatrix = new CampaignMatrix();
foreach($list as $index => $item) {
$itemAssocForm = new CampaignMatrixForm($CampaignMatrix);
$itemAssocForm->item_id = $item->getId(); // Need it in the form as hidden field
$this->embedForm($item->getProductId(), $itemAssocForm);
}
And this is how I'm trying to get the value:
$this->widgetSchema['item_id'] = new sfWidgetFormInputText(array(), array('value' => $this->item_id)); // It doesn't get the Id
But I have an error:
Fatal error: Maximum execution time of 30 seconds exceeded in /vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Relation/Parser.php on line 237
If I unset price_id in CampaignMatrixForm, no error produced. How to avoid execution of select of the same data for every item row in the loop?
Item id is missing, but I need it as hidden field. How to pass CampaignMatrix ID of current row to CampaignMatrixForm?
You have to iterate on association to emebed the association form to the main form. It mays be simple if you post a part of your schema.yml.
Try to re-use this snippet :
$list = MyRelatedObjectTable::getInstance()->findAll();
foreach($list as $item)
{
$itemAssoc = AssociationTable::getInstance()->findByObjectId($this->object->id, $item->id);
if(!$itemAssoc)
{
$itemAssoc = new Association();
$itemAssoc->value_id = $itemAssoc->id;
$itemAssoc->user_id = $this->object->id;
}
$itemAssocForm = new AssociationForm($itemAssoc);
$this->embedForm('itemAssoc'.$item->code, $itemAssocForm);
}
The best way is to create a partial for that. Be aware that you need to unset the select box for the Item in the Form class or you'll lose your association. I can elaborate on that if you need more help.
you can get code from cache and move to your backend/modules/nameAPP and next edit template
here is my schema.yml files:
issues:
actAs: { Timestampable: ~ }
columns:
issueId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
issueDateForPublish: { type: timestamp, notnull: true }
issueName: { type: string(255), notnull: true }
issueCoverArticleId: { type: integer(4), notnull: true }
relations:
articles:
class: articles
foreignAlias: article
local: articleId
foreign: issueId
type: many
articles:
actAs: { Timestampable: ~ }
columns:
articleId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
articleTitle: { type: string(), notnull: true }
articleText: { type: string(), notnull: true }
articleDataForPublish: { type: timestamp, notnull: true }
articleIsDraft: { type: boolean, notnull: true, default: 1 }
articleIsOnHold: { type: boolean, notnull: true, default: 0 }
articleIsModerate: { type: boolean, notnull: true, default: 0 }
articleIsApprove: { type: boolean, notnull: true, default: 0 }
relations:
articles:
local: issueId
foreign: articleId
onDelete: cascade
comments:
class: comments
foreignAlias: comment
local: commentId
foreign: articleId
type: many
comments:
actAs: { Timestampable: ~ }
columns:
commentId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
commentName: { type: string(255), notnull: true }
commentSurname: { type: string(255), notnull: true }
commentMail: { type: string(255), notnull: true }
commentDataForPublish: { type: timestamp }
commentIsModerated: { type: boolean, notnull: true, default: 0 }
commentIsApprove: { type: boolean, notnull: true, default: 0 }
relations:
articles:
local: articleId
foreign: commentId
onDelete: cascade
Again, when i run php symfony doctrine:build --model and php symfony doctrine:build --sql nothing goes bad. "php symfony doctrine:insert-sql" makes this error:
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'issueid' doesn't exist in table. Failing Query: "CREATE TABLE articles (articleid INT AUTO_INCREMENT, articletitle TEXT NOT NULL, articletext TEXT NOT NULL, articledataforpublish DATETIME NOT NULL, articleisdraft TINYINT(1) DEFAULT '1' NOT NULL, articleisonhold TINYINT(1) DEFAULT '0' NOT NULL, articleismoderate TINYINT(1) DEFAULT '0' NOT NULL, articleisapprove TINYINT(1) DEFAULT '0' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX issueid_idx (issueid), PRIMARY KEY(articleid)) ENGINE = INNODB". Failing Query: CREATE TABLE articles (articleid INT AUTO_INCREMENT, articletitle TEXT NOT NULL, articletext TEXT NOT NULL, articledataforpublish DATETIME NOT NULL, articleisdraft TINYINT(1) DEFAULT '1' NOT NULL, articleisonhold TINYINT(1) DEFAULT '0' NOT NULL, articleismoderate TINYINT(1) DEFAULT '0' NOT NULL, articleisapprove TINYINT(1) DEFAULT '0' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX issueid_idx (issueid), PRIMARY KEY(articleid)) ENGINE = INNODB
Thanks for your help, erman.
You've got your definition a bit wrong.
Local should be the name of the field in the current table, and foreign the field in the foreign table - you have these the wrong way round.
You normally only define one end of the relationship - doctrine auto adds the inverse to the other table, and gets it right 99% of the time. If you do it manually they have to match. In this case, remove the article relation from issues, and the comments relation from articles.
Comments has no article id field.
Foreign alias isn't needed, but you have it the wrong way round - its what the current table/object will be referred to as in the table/object at the far end of the relation. Defaults to the name of the current object, so can often ignore.
Few other minor niggles too. At a guess, I reckon this schema will do you:
issue:
actAs: { Timestampable: ~ }
columns:
issueId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
issueDateForPublish: { type: timestamp, notnull: true }
issueName: { type: string(255), notnull: true }
issueCoverArticleId: { type: integer(4), notnull: true }
article:
actAs: { Timestampable: ~ }
columns:
articleId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
articleTitle: { type: string(), notnull: true }
articleText: { type: string(), notnull: true }
articleDataForPublish: { type: timestamp, notnull: true }
articleIsDraft: { type: boolean, notnull: true, default: 1 }
articleIsOnHold: { type: boolean, notnull: true, default: 0 }
articleIsModerate: { type: boolean, notnull: true, default: 0 }
articleIsApprove: { type: boolean, notnull: true, default: 0 }
issueId: { type: integer(4) }
relations:
issue:
local: issueId
foreign: issueId
foreignAlias: articles
onDelete: cascade
comment:
actAs: { Timestampable: ~ }
columns:
commentId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
commentName: { type: string(255), notnull: true }
commentSurname: { type: string(255), notnull: true }
commentMail: { type: string(255), notnull: true }
commentDataForPublish: { type: timestamp }
commentIsModerated: { type: boolean, notnull: true, default: 0 }
commentIsApprove: { type: boolean, notnull: true, default: 0 }
articleId: { type: integer(4) }
relations:
article:
local: articleId
foreign: articleId
onDelete: cascade
foreignAlias: comments
I have a Heading table/model and I also have a "heading" module. When I go to the heading module, which has worked fine in the past, it now gives me this error:
Cannot generate a module for a model without a primary key (Heading)
This is odd to me because my schema.yml for Heading looks like this:
Heading:
connection: doctrine
tableName: heading
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
referenced_table_name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
column_name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
label:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
position:
type: integer(4)
fixed: false
unsigned: true
primary: false
notnull: true
autoincrement: false
import_profile_id:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
note:
type: string()
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
default: '0000-00-00 00:00:00'
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
default: '0000-00-00 00:00:00'
notnull: true
autoincrement: false
relations:
ImportProfile:
local: import_profile_id
foreign: id
type: one
TotalFromFile:
local: id
foreign: heading_id
type: many
Note the primary key:
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
I suspect it has something to do with this other problem I'm having. Any ideas?
Turns out the problem was that I had defined HeadingTable::getTables() and HeadingTable::getColumns(). Doctrine didn't like that.
I've got a MySQL 5.1.41 database which i'm trying to fill with doctrine, but doctrine does not insert the relations correctly. My YAML is:
Locatie:
connection: doctrine
tableName: locatie
columns:
loc_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
org_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
naam:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
straat:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
huisnummer:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
huisnummer_achtervoegsel:
type: string(3)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
plaats:
type: string(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
postcode:
type: string(6)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
telefoon:
type: string(12)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
opmerking:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
inloggegevens:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Organisatie:
local: org_id
foreign: org_id
type: one
onDelete: CASCADE
onUpdate: CASCADE
Organisatie:
connection: doctrine
tableName: organisatie
columns:
org_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
naam:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
straat:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
huisnummer:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
huisnummer_achtervoegsel:
type: string(3)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
plaats:
type: string(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
postcode:
type: string(6)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
telefoon:
type: string(12)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
opmerking:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Locatie:
local: org_id
foreign: org_id
type: many
Now if a make an organisation and then create a location which has a foreignkey to organisation everything is fine. but when i try to update the org_id with phpmyadmin i get a contraint error. If i manually set the foreign key to ON_UPDATE CASCADE it does work.
Why does doctrine not set this option?
I got it to work in Propel, but i really want to use doctrine for this.
Well, you can't update the org_id because it's referenced by the location table. If you change it, it would mean that the organisation has a location that does not exist --- the foreign key fails. Insert your location data in first, and then all the location values become possible values for organisations, or alternatively use onCascade actions as you mention.
Also, something you can do is define the Organisatie table first, and include the relation declaration only for this table (one definition is enough for Doctrine). Now the Locatie table becomes referenced, and you can play with its keys freely. Of course, you still cannot reference something from the Organisatie table that does not exist.
I also spot that your schema currently says that "one organisation has many locations" although I'm guessing you've intended "one location has many organisations". If this is indeed the case, change the Organisatie->relations->Locatie to "type: one, foreignType: many", and remove the relationship declaration from your Locatie table.
Hope that helps.