Ticket #963 (closed defect: fixed)
Generate Sql produces incorrect sql
| Reported by: | jfung | Owned by: | jwage |
|---|---|---|---|
| Priority: | critical | Milestone: | 0.11.0 |
| Component: | Tasks | Version: | 0.11.0 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | ||
| Status: | Has Patch: |
Description
After running the command generate-sql to create an sql file, the generated sql misses certain contraints. Here's the example
User.yml
---
User:
columns:
id:
type: integer(4)
primary: true
autoincrement: true
username:
type: string(255)
password:
type: string(255)
Email:
columns:
user_id:
type: integer(4)
primary: true
address:
type: string(255)
relations:
User:
local: user_id
foreign: id
foreignType: one
onDelete: CASCADE
BaseUser?.php
abstract class BaseUser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('user');
$this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$this->hasColumn('username', 'string', 255);
$this->hasColumn('password', 'string', 255);
}
public function setUp()
{
parent::setUp();
$this->hasOne('Email', array('local' => 'id',
'foreign' => 'user_id'));
}
}
BaseEmail?.php
abstract class BaseEmail extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('email');
$this->hasColumn('user_id', 'integer', 4, array('primary' => true));
$this->hasColumn('address', 'string', 255);
}
public function setUp()
{
parent::setUp();
$this->hasOne('User', array('local' => 'user_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
}
Generated SQL
CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(255), password VARCHAR(255)); CREATE TABLE email (user_id INTEGER, address VARCHAR(255), PRIMARY KEY(user_id));
Change History
Note: See
TracTickets for help on using
tickets.