Hey Maxime! First I have to say to you that doing relations with symfony and doctrine is a little bit tricky.
Unfortunately there is just one nice tutorial which I can recommend: http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms Another good hint is reading the doctrine documentation: http://www.doctrine-project.org/documentation Bye Stefan On 12 Feb., 07:24, Maxime Lepreux <maxime.lepr...@gmail.com> wrote: > Hi. > > French developper, I 'm new to symphony. > > Trying to understand how doctrine works, i've been using > doctrine:commands (buid-schema or build-model/build-sql) > > environment : > WAMPSERVER (Apache 2, PHP 5, Mysql 5) > Symfony 1.4 stable > db generated via MYSQL Workbench > > CREATE TABLE IF NOT EXISTS `myjobsearch`.`table1` ( > `id` INT NOT NULL AUTO_INCREMENT , > `field01` VARCHAR(45) NOT NULL , > PRIMARY KEY (`id`) ) > ENGINE = InnoDB; > > CREATE TABLE IF NOT EXISTS `myjobsearch`.`table2` ( > `id` INT NOT NULL , > `field01` VARCHAR(45) NOT NULL , > PRIMARY KEY (`id`) , > INDEX `fk_table2_table1` (`id` ASC) , > CONSTRAINT `fk_table2_table1` > FOREIGN KEY (`id` ) > REFERENCES `myjobsearch`.`table1` (`id` ) > ON DELETE NO ACTION > ON UPDATE NO ACTION) > ENGINE = InnoDB; > > on first attempt : > - first i've used build-schema from mysql to get a correct schema.yml > file > > Table1: > connection: doctrine > tableName: table1 > columns: > id: > type: integer(4) > fixed: false > unsigned: false > primary: true > autoincrement: true > field01: > type: string(45) > fixed: false > unsigned: false > primary: false > notnull: true > autoincrement: false > relations: > Table2: > local: id > foreign: id > type: many > Table2: > connection: doctrine > tableName: table2 > columns: > id: > type: integer(4) > fixed: false > unsigned: false > primary: true > autoincrement: false > field01: > type: string(45) > fixed: false > unsigned: false > primary: false > notnull: true > autoincrement: false > relations: > Table1: > local: id > foreign: id > type: one > > Question 1: why has doctrine generated a one-to-many relation instaed > of one-to-one? > > Going on ,ignoring this question, using build-model command:. > > the result is that BaseTable1 has in setup() : > ... > $this->hasMany('Table2', array( > 'local' => 'id', > 'foreign' => 'id')); > > has many() not matching the db ! > > on second attempt : > modifiing schema.yml on relation table1->table2 to match on db model > Table1: > ... > relations: > Table2: > local: id > foreign: id > type: many > Table2: > ... > relations: > Table1: > local: id > foreign: id > type: one > > and rebuild model files : great ! i've got to hasone() on both base > classes. > > so now , using build-sql command to generate schema.sql: > > CREATE TABLE table1 (id INT AUTO_INCREMENT, field01 VARCHAR(45) NOT > NULL, PRIMARY KEY(id)) ENGINE = INNODB; > CREATE TABLE table2 (id INT, field01 VARCHAR(45) NOT NULL, PRIMARY > KEY(id)) ENGINE = INNODB; > > Question 2 :huuuu... Dude, were's my FK constraint ? > > this tiny example demonstrates i definitly don't understand > doctrine( or yaml) works > is there any tuto explaining basics of yaml syntax for relations > ( 1-1, 1-n, n-n) > with WORKING db->build-schema->build-model->build-sql->insert sql ? > thanks -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en.