I seem to be sitting on some cable, because I can't find a solution to a seemingly easy problem.
What I need is a OneToOne Relationship in which both objects hold their counterpart in an instance variable. Something like married couples. Husbands should know their wife, but wives should also know their husband. The classes look something like: Man class iVars: name, birthday, ... and wife Woman class iVars: name, birthday, ... and husband here's what the descriptor for the Man Class / Table would look like: (aDescriptor newMapping: OneToOneMapping) attributeName: #wife; referenceClass: Woman; mappingCriteria: ( Join from: (table fieldNamed: 'wife_id') to: ((self tableNamed: 'WOMAN') fieldNamed: 'id')) Since the model I am working on is a bit more complex, adding a column 'husband_id' to the WOMAN table is not an option I would prefer. I'd like to add a backpointer to the mappings that uses the 'wife_id' column in the MAN table to determine which man to put into the #husband instance variable. So how can I make this relationship navigable from both sides without adding another id to the WOMAN table? I guess it's not too hard, but you know how it goes.. Joachim
-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
Did you think about using a link table ?
> "jtuchel" <[hidden email]> | I seem to be sitting on some cable, because I can't find a solution to a seemingly easy problem. What I need is a OneToOne Relationship in which both objects hold their counterpart in an instance variable. Something like married couples. Husbands should know their wife, but wives should also know their husband.
The classes look something like:
Man class iVars: name, birthday, ... and wife
Woman class iVars: name, birthday, ... and husband
here's what the descriptor for the Man Class / Table would look like:
(aDescriptor newMapping: OneToOneMapping)
attributeName: #wife;
referenceClass: Woman;
mappingCriteria: (
Join
from: (table fieldNamed: 'wife_id')
to: ((self tableNamed: 'WOMAN') fieldNamed: 'id'))
Since the model I am working on is a bit more complex, adding a column 'husband_id' to the WOMAN table is not an option I would prefer. I'd like to add a backpointer to the mappings that uses the 'wife_id' column in the MAN table to determine which man to put into the #husband instance variable.
So how can I make this relationship navigable from both sides without adding another id to the WOMAN table? I guess it's not too hard, but you know how it goes..
Joachim
-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
Well, no. A link table would make things even more complex, wouldn't it?
Am Mittwoch, 26. Juni 2013 11:48:35 UTC+2 schrieb [hidden email]: -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
No I think it is pretty straith forward, also there must be quite some examples out there to do so. Give it a try .. @+Maarten,
> "jtuchel" <[hidden email]> | Well, no. A link table would make things even more complex, wouldn't it? -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
In reply to this post by jtuchel
That should just work. On the wife side you just have an attribute #husband whose join is from id to wife_id. In fact, in the absence of polygamy, you should be able to leave off the join and let Glorp figure it out. If it knows the class, and there's only one join that would work between the tables those classes are mapped to, it will use it automatically.
On 26 June 2013 00:36, jtuchel <[hidden email]> wrote: I seem to be sitting on some cable, because I can't find a solution to a seemingly easy problem. You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
It is a real pain however when husband and wife seperate and go there way with differents partners. Often the update doesn't get through. At least with a link table you can surpress the mariage refresh partners and rebuild life from there ...
> "Alan Knight" <[hidden email]> | That should just work. On the wife side you just have an attribute #husband whose join is from id to wife_id. In fact, in the absence of polygamy, you should be able to leave off the join and let Glorp figure it out. If it knows the class, and there's only one join that would work between the tables those classes are mapped to, it will use it automatically.
On 26 June 2013 00:36, jtuchel <[hidden email]> wrote:
I seem to be sitting on some cable, because I can't find a solution to a seemingly easy problem. You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
In reply to this post by Alan Knight-2
Alan,
-- I just came back to this issue and found out it simply does work ;-) I was somewhat irritated by the fact that the foreign key is located in the root table and not in the dependent table (as it normally is in 1:n relationships). Thanks for answering Joachim Am Mittwoch, 26. Juni 2013 16:19:58 UTC+2 schrieb Alan Knight:
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/groups/opt_out. |
Free forum by Nabble | Edit this page |