I'm probably in too deep here, but I've defined a custom model and I'm inserting relational data in a way so that I can avoid explicitly setting primary keys (since they are just database artifacts and have nothing inherently to do with the objects being stored).
It goes a little something like this:
$ParentObj = $this->modx->newObject('ParentClass');
$ParentObj->fromArray($ParentObjdata); // an array WITHOUT the primary key
$Child = $this->modx->newObject('ChildClass');
$Child->fromArray($ChildObjdata); // everything BUT not the specific foreign key to the parent obj
// This triggers validation errors:
if (!$ParentObj->addOne($Child)) {
$validator = $Child->getValidator();
if ($validator->validate() == false) {
$messages = $validator->getMessages();
foreach ($messages as $m) {
print_r($m);
}
}
};
$ParentObj->save(); // only NOW do we know the primary key
However, in my schema, I'm using xPDOForeignKeyConstraint xPDOValidationRule validation rules in the Child object to make sure that the parent object exists. The problem is that it seems that the validation rule in the Child seems to executes when addOne or addMany is called and BEFORE the parent object has been saved.
In the above example you can see that the $ParentObj isn't saved until AFTER the children objects are added. Is there any hope here? I could get the last insert id and rework it, but it does defeat the purpose of having the validation rule. Maybe it's possible to override the Validator behavior?
[ed. note: Everettg_99 last edited this post 12 years, 4 months ago.]