Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Versionable behavior, error with fk in baseX Class #282

Closed
aamsellem opened this Issue Feb 6, 2012 · 4 comments

Comments

Projects
None yet
3 participants
Contributor

aamsellem commented Feb 6, 2012

I got a problem with generated class using versionable behavior in the function "populateFromVersion"

The problem appears when we use two or more tables with the versionable behavior and one of them have a id field with a fieldname not equal to "id".

It's work if two id's name is "ID" because ID field exist in both table but if one id field name is different the error appear.

schema :
A:
diff_id : { type: integer, required: true, primaryKey: true, autoIncrement: true, phpName: Id }
_propel_behaviors:

versionable: { log_created_at: true, log_created_by: true}
B:
id: ~
a_id: { type: integer, foreignTable: a, foreignReference: diff_id, default : null }
_propel_behaviors:

versionable: { log_created_at: true, log_created_by: true}

It will generate in baseA :

$c1 = $query->getNewCriterion(BPeer::DIFF_ID, $value);

instead of

$c1 = $query->getNewCriterion(BPeer::ID, $value);

in that case $query is a BQuery object.

It's seems that the problem come from here : a54ac77

Contributor

aamsellem commented Feb 6, 2012

I think if you replace in the file generator/lib/behavior/versionable/VersionableBehaviorObjectBuilderModifier.php:

L.151 : $fkColumn = $fk->getForeignColumn();

with

L.151 : $fkColumn = $foreignVersionTable->getFirstPrimaryKeyColumn();

it fix the problem.

Member

fzaninotto commented Feb 6, 2012

Could you create a unit test showing the problem, and proving that your fix works?

Contributor

aamsellem commented Feb 6, 2012

I can't today, but I will try ASAP.

@aamsellem aamsellem added a commit to aamsellem/Propel that referenced this issue Feb 6, 2012

@aamsellem aamsellem Fix #282 versionable behavior FK in generated object classes
Fix #282 by replacing foreign key references with PrimaryKey
+ Add Phpunit test
b1f651f
Contributor

aamsellem commented Feb 6, 2012

Finally I found some time to work on.

@aamsellem aamsellem closed this Feb 6, 2012

@aamsellem aamsellem reopened this Feb 6, 2012

@aamsellem aamsellem added a commit to aamsellem/Propel that referenced this issue Feb 7, 2012

@aamsellem aamsellem Fix #282 version able behavior FK in generated object class
Fix #282 by replacing foreign key references with PrimaryKey
+ Add Phpunit test
24ef626

@willdurand willdurand closed this in 5ebefc3 Mar 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment