Re: [Pharo-users] Group and member with Voyage
That was the main error I had. Assuming the #isVoyageRoot was inheritable. After looking at #voyageCollectionName I understood all the problems I had. I learnt a lot about its internal during the process. Design question: Why #persistentClass answer false if a Class has no voyage root superclass? Shouldn't it raise an error or answer nil instead? Esteban A. Maringolo 2013/9/10 Esteban Lorenzano esteba...@gmail.com no, it should not be implemented, no need to make him answer false (in fact, I never tried, but I'm pretty sure that is you reimplement isVoyageRoot to answer false in the subclasses most probably you will get a class that is transient :( ). reason is that voyage looks the root class of a hierarchy by noticing where is #isVoyageRoot = true implemented. (again, each time I look in this design decisions I feel a bit ashamed... but well, they looked good at the moment :) ) Esteban On Sep 10, 2013, at 5:06 PM, Esteban A. Maringolo emaring...@gmail.com wrote: Esteban, I didn't know about the #isVoyageRoot difference based on where was the method defined. I mean... if I define Member class#isVoyageRoot ^true why sould SingleMember answer false? Do I have to redefine it to answer false in each of Member subclasses? Regards! Esteban A. Maringolo 2013/9/10 Esteban Lorenzano esteba...@gmail.com Hi, what happens is that if you declare a kind, you forces all elements to be of that specific class. Solution is just not add that property: mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; -- NO! beLazy; yourself. And same happens in the mongoContainer description in the top of your hierarchy... you must NOT declare a kind. Also, if you want all members to go in just one collection. #isVoyageRoot has to be implemented in the top of the hierarchy and not in the subclasses Member -- #isVoyageRoot = true here! SingleMember ComplexMember what happens then is that voyage will create a collection and for each document it stores in it will also store the attribute '#instanceOf', which will be used to retrieve the correct object. Esteban what happens then is that On Aug 31, 2013, at 12:53 AM, Esteban A. Maringolo emaring...@gmail.com wrote: More or less, I have this working. In the Group class I have a description named: descriptionMembers mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; beLazy; yourself And in the Member class I have descriptionGroups mongoDescription ^VOMongoToManyDescription new attributeName: 'groups'; accessor: #groups; kind: Group; beLazy; yourself But what if Member is an abstract class and the elements can be any of SingleMember or ComplexMember?, each one is stored in a separate collection in Mongo. If I do specify #kind: Member in my #descriptionMembers it won't work. Any ideas? Regards, Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: 2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
Re: [Pharo-users] Group and member with Voyage
Esteban, I didn't know about the #isVoyageRoot difference based on where was the method defined. I mean... if I define Member class#isVoyageRoot ^true why sould SingleMember answer false? Do I have to redefine it to answer false in each of Member subclasses? Regards! Esteban A. Maringolo 2013/9/10 Esteban Lorenzano esteba...@gmail.com Hi, what happens is that if you declare a kind, you forces all elements to be of that specific class. Solution is just not add that property: mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; -- NO! beLazy; yourself. And same happens in the mongoContainer description in the top of your hierarchy... you must NOT declare a kind. Also, if you want all members to go in just one collection. #isVoyageRoot has to be implemented in the top of the hierarchy and not in the subclasses Member -- #isVoyageRoot = true here! SingleMember ComplexMember what happens then is that voyage will create a collection and for each document it stores in it will also store the attribute '#instanceOf', which will be used to retrieve the correct object. Esteban what happens then is that On Aug 31, 2013, at 12:53 AM, Esteban A. Maringolo emaring...@gmail.com wrote: More or less, I have this working. In the Group class I have a description named: descriptionMembers mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; beLazy; yourself And in the Member class I have descriptionGroups mongoDescription ^VOMongoToManyDescription new attributeName: 'groups'; accessor: #groups; kind: Group; beLazy; yourself But what if Member is an abstract class and the elements can be any of SingleMember or ComplexMember?, each one is stored in a separate collection in Mongo. If I do specify #kind: Member in my #descriptionMembers it won't work. Any ideas? Regards, Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: 2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
Re: [Pharo-users] Group and member with Voyage
I just answered that :) On Sep 10, 2013, at 5:00 PM, Esteban A. Maringolo emaring...@gmail.com wrote: Esteban, That's totally fine for me. I've been doing explicit saves in ORMs since more than a decade. I can live with that. My question was to have more than one class of element in the same collection mapping. Regards! Esteban A. Maringolo 2013/9/10 Esteban Lorenzano esteba...@gmail.com Hi, I just found some time to see this... there is a problem with saving/updating circular references that I solved by not solve it at all :( here is the thing: when you create a new group and add a new user, the #save message will find the new objects (in this case group and user) and save both. Now, when you are updating, I do not have any way (so far), to know which part of the graph is actually updated and needs to be saved (and we all will agree that persisting each time all structure will not be efficient). So I just do not do it, I'm sorry :( That mean that if the referenced object is not new, it is not stored... just the first level object is... I know is not a good solution, but what I do is to save each element of the graph separated: user := User new save. group := Group new add: user; save. so, taking each updated element as a unity will do the job. I know, I know... this is not optimal (and in fact is pretty bad), but well... is what I could do at the moment and never had the time to enhance it. Esteban On Aug 30, 2013, at 3:12 AM, Esteban A. Maringolo emaring...@gmail.com wrote: Hi all, Let's say I have a class Group and a class Member. aGroup has many members. and aMember can belong to many groups. What is the proper voyageDescription for those one to many relations? Should I do something extra? Everytime I add a member to the group, both the member and the group get their references updated. Now when I add a member to a group and save it, I also save the member. Is there another way to avoid this? Any recommended practice for this? Next level question: What if it gets composite? it is... a Group has other Groups as members :) Regards! Esteban A. Maringolo
Re: [Pharo-users] Group and member with Voyage
Esteban, That's totally fine for me. I've been doing explicit saves in ORMs since more than a decade. I can live with that. My question was to have more than one class of element in the same collection mapping. Regards! Esteban A. Maringolo 2013/9/10 Esteban Lorenzano esteba...@gmail.com Hi, I just found some time to see this... there is a problem with saving/updating circular references that I solved by not solve it at all :( here is the thing: when you create a new group and add a new user, the #save message will find the new objects (in this case group and user) and save both. Now, when you are updating, I do not have any way (so far), to know which part of the graph is actually updated and needs to be saved (and we all will agree that persisting each time all structure will not be efficient). So I just do not do it, I'm sorry :( That mean that if the referenced object is not new, it is not stored... just the first level object is... I know is not a good solution, but what I do is to save each element of the graph separated: user := User new save. group := Group new add: user; save. so, taking each updated element as a unity will do the job. I know, I know... this is not optimal (and in fact is pretty bad), but well... is what I could do at the moment and never had the time to enhance it. Esteban On Aug 30, 2013, at 3:12 AM, Esteban A. Maringolo emaring...@gmail.com wrote: Hi all, Let's say I have a class Group and a class Member. aGroup has many members. and aMember can belong to many groups. What is the proper voyageDescription for those one to many relations? Should I do something extra? Everytime I add a member to the group, both the member and the group get their references updated. Now when I add a member to a group and save it, I also save the member. Is there another way to avoid this? Any recommended practice for this? Next level question: What if it gets composite? it is... a Group has other Groups as members :) Regards! Esteban A. Maringolo
Re: [Pharo-users] Group and member with Voyage
Hi, what happens is that if you declare a kind, you forces all elements to be of that specific class. Solution is just not add that property: mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; -- NO! beLazy; yourself. And same happens in the mongoContainer description in the top of your hierarchy... you must NOT declare a kind. Also, if you want all members to go in just one collection. #isVoyageRoot has to be implemented in the top of the hierarchy and not in the subclasses Member -- #isVoyageRoot = true here! SingleMember ComplexMember what happens then is that voyage will create a collection and for each document it stores in it will also store the attribute '#instanceOf', which will be used to retrieve the correct object. Esteban what happens then is that On Aug 31, 2013, at 12:53 AM, Esteban A. Maringolo emaring...@gmail.com wrote: More or less, I have this working. In the Group class I have a description named: descriptionMembers mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; beLazy; yourself And in the Member class I have descriptionGroups mongoDescription ^VOMongoToManyDescription new attributeName: 'groups'; accessor: #groups; kind: Group; beLazy; yourself But what if Member is an abstract class and the elements can be any of SingleMember or ComplexMember?, each one is stored in a separate collection in Mongo. If I do specify #kind: Member in my #descriptionMembers it won't work. Any ideas? Regards, Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: 2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
Re: [Pharo-users] Group and member with Voyage
Am 31.08.2013 um 02:18 schrieb Esteban A. Maringolo emaring...@gmail.com: I think that the question could be rephrased as: How to map a collection with elements of different classes? Am I asking for too much? No, but this isn't a trivial problem. For your specific case it is probably not implemented. I still didn't find the time to look into voyage but I think it has basically two modes: Either you use it plain (no magritte) and types are inferred from the object. Voyage then adds the information about the class in the json being serialized. If you use magritte then it can take the information from the description. So your case is a mix of the two. You can take basic information from the description but if it comes to inheritance you still need to add the class information in the json to be able to deserialize properly. The sad story about this is that relationships aren't perfect in magritte and nobody finds time to work out a proper solution. For your case and other problems there needs to be a fix and having separate descriptions for homogenous and heterogenous collections might be an approach that solves a few things. Norbert Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: More or less, I have this working. In the Group class I have a description named: descriptionMembers mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; beLazy; yourself And in the Member class I have descriptionGroups mongoDescription ^VOMongoToManyDescription new attributeName: 'groups'; accessor: #groups; kind: Group; beLazy; yourself But what if Member is an abstract class and the elements can be any of SingleMember or ComplexMember?, each one is stored in a separate collection in Mongo. If I do specify #kind: Member in my #descriptionMembers it won't work. Any ideas? Regards, Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: 2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
Re: [Pharo-users] Group and member with Voyage
2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
Re: [Pharo-users] Group and member with Voyage
More or less, I have this working. In the Group class I have a description named: descriptionMembers mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; beLazy; yourself And in the Member class I have descriptionGroups mongoDescription ^VOMongoToManyDescription new attributeName: 'groups'; accessor: #groups; kind: Group; beLazy; yourself But what if Member is an abstract class and the elements can be any of SingleMember or ComplexMember?, each one is stored in a separate collection in Mongo. If I do specify #kind: Member in my #descriptionMembers it won't work. Any ideas? Regards, Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: 2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
Re: [Pharo-users] Group and member with Voyage
I think that the question could be rephrased as: How to map a collection with elements of different classes? Am I asking for too much? Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: More or less, I have this working. In the Group class I have a description named: descriptionMembers mongoDescription ^VOMongoToManyDescription new attributeName: 'members'; accessor: #members; kind: Member; beLazy; yourself And in the Member class I have descriptionGroups mongoDescription ^VOMongoToManyDescription new attributeName: 'groups'; accessor: #groups; kind: Group; beLazy; yourself But what if Member is an abstract class and the elements can be any of SingleMember or ComplexMember?, each one is stored in a separate collection in Mongo. If I do specify #kind: Member in my #descriptionMembers it won't work. Any ideas? Regards, Esteban A. Maringolo 2013/8/30 Esteban A. Maringolo emaring...@gmail.com: 2013/8/30 James Foster smallt...@jgfoster.net: It seems that I mistook the question for something easy enough for me to answer! Unfortunately, I don't have any knowledge of Voyage+MongoDB so can't really give the proper answer. Thanks anyway, it is a problem you'll never find in GemStone/S ;-)
[Pharo-users] Group and member with Voyage
Hi all, Let's say I have a class Group and a class Member. aGroup has many members. and aMember can belong to many groups. What is the proper voyageDescription for those one to many relations? Should I do something extra? Everytime I add a member to the group, both the member and the group get their references updated. Now when I add a member to a group and save it, I also save the member. Is there another way to avoid this? Any recommended practice for this? Next level question: What if it gets composite? it is... a Group has other Groups as members :) Regards! Esteban A. Maringolo