#1640: Foreign Keys for Self-referencing (Nest relations) not created for both
columns
------------------------+---------------------------------------------------
Reporter: hal | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.0.5
Component: Relations | Version: 1.0.3
Resolution: | Keywords:
Has_test: 0 | Mystatus: Pending Core Response
Has_patch: 0 |
------------------------+---------------------------------------------------
Old description:
> Platform: Win XP Pro SP2, PHP: 5.2.5, DBMS: Postgresql 8.3.1, Symfony:
> 1.1.5-DEV, Doctrine: 1.0.3,
>
> Note: This example is tested using symfony, by building the schema.yml
> file and then executing the following command: symfony doctrine:build-
> all-reload appname
>
> This ticket has been moved from http://trac.symfony-
> project.org/ticket/4824, after jwage confirmed that it is a doctrine
> rather than a sfDoctrinePlugin bug.
>
> The example code at http://www.doctrine-
> project.org/documentation/manual/1_0/?one-page#relations:join-table-
> associations:self-referencing-nest-relations:non-equal-nest-relations
> does not seem to work correctly. When the database has been created and
> sql inserted, the UserReference? table only has one foreign key to the
> User table, rather than a FK on both of its columns. This does not
> correctly enforce data integrity
>
> As I presume this is an oversight in the code rather than simply in the
> documentation, I have raised it as a defect rather than an enhancement
> request due its severity, bearing in mind that it could have impacts on
> the robustness of the relationship and hence accuracy of user data.
New description:
Platform: Win XP Pro SP2, PHP: 5.2.5, DBMS: Postgresql 8.3.1, Symfony:
1.1.5-DEV, Doctrine: 1.0.3,
Note: This example is tested using symfony, by building the schema.yml
file and then executing the following command: symfony doctrine:build-all-
reload appname
This ticket has been moved from http://trac.symfony-
project.org/ticket/4824, after jwage confirmed that it is a doctrine
rather than a sfDoctrinePlugin bug.
The example code at http://www.doctrine-
project.org/documentation/manual/1_0/?one-page#relations:join-table-
associations:self-referencing-nest-relations:non-equal-nest-relations does
not seem to work correctly. When the database has been created and sql
inserted, the UserReference? table only has one foreign key to the User
table, rather than a FK on both of its columns. This does not correctly
enforce data integrity
As I presume this is an oversight in the code rather than simply in the
documentation, I have raised it as a defect rather than an enhancement
request due its severity, bearing in mind that it could have impacts on
the robustness of the relationship and hence accuracy of user data.
Comment (by hal):
Hi floriank - thanks for your reply.
I have tried your suggestion, but refClassRelationAlias does not seem to
have any effect.
I am still not able to see the two hasOne relations from the
!UserReference class to the User class, and I only see one FK (on
parent_id) created in the database.
Here is my schema.yml code:
{{{
User:
tableName: test_user
columns:
name: string(30)
relations:
Parents:
class: User
refClass: UserReference
refClassRelationAlias: Parents1
local: parent_id
foreign: child_id
Children:
class: User
refClass: UserReference
refClassRelationAlias: Children2
local: child_id
foreign: parent_id
UserReference:
tableName: test_reference
columns:
parent_id:
type: integer
primary: true
child_id:
type: integer
primary: true
}}}
Here are the classes that are automaically generated:
{{{
abstract class BaseUser extends sfDoctrineRecord
{
public function setTableDefinition()
{
$this->setTableName('test_user');
$this->hasColumn('name', 'string', 30, array('type' => 'string',
'length' => '30'));
}
public function setUp()
{
$this->hasMany('User as Parents', array('refClass' => 'UserReference',
'refClassRelationAlias' =>
'Parents1',
'local' => 'parent_id',
'foreign' => 'child_id'));
$this->hasMany('User as Children', array('refClass' =>
'UserReference',
'refClassRelationAlias' =>
'Children2',
'local' => 'child_id',
'foreign' => 'parent_id'));
}
abstract class BaseUserReference extends sfDoctrineRecord
{
public function setTableDefinition()
{
$this->setTableName('test_reference');
$this->hasColumn('parent_id', 'integer', null, array('type' =>
'integer', 'primary' => true));
$this->hasColumn('child_id', 'integer', null, array('type' =>
'integer', 'primary' => true));
}
}}}
--
Ticket URL: <http://trac.doctrine-project.org/ticket/1640#comment:2>
Doctrine <http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"doctrine-svn" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---