Hi there,
it's me, fighting either Glorp or my ignorance - maybe the latter is more likely, dunno.
I have a class, which is mapped to a single table, and each instance of this class can have a copy of itself. This derived copy lives in the same table and also knows the instance it is a copy of.
So there is my class with these inst vars:
- id
- version
- copy
- original
(an instance can either have a copy or an original, but never both)
The table has the following columns:
* id
* version
* orginal_id
(which means the copy row has a foreign key to the original row in the very same table)
I tried quite a few approaches to map this, but either end up having strange effects when I register: a copy with the session (UpdateCommand gets instantiated instead of InsertCommand, and its owner is the original instead or the copy) , or I get Proxies on UndefinedObjects when reading an original that has no copy.
I thought the best possible way to map this would be this descriptor snippet, but it doesn't work (all objects always get materialized with an invalid Proxy for #copy):
(aDescriptor newMapping: OneToOneMapping)
attributeName: #copy;
referenceClass: MyClass;
mappingCriteria: (
Join
from: (table fieldNamed: 'id')
to: (table fieldNamed: 'original_id')).
(aDescriptor newMapping: OneToOneMapping)
attributeName: #original;
referenceClass: MyClass;
mappingCriteria: (
Join
from: (table fieldNamed: 'original_id')
to: (table fieldNamed: 'id')).
Any ideas what I am doing wrong? What do I have to do to make this work?
Joachim