Question about GLORP class models
Hi guys! Iâm trying to use GLORP and Iâm having problems defining the class model for a class which has an instance variable which is a collection of instances of two different classes: I have 3 classes named: { Section . Question . QuestionGroup } and I have problems for specifying the glorp class model for Section. Object subclass: #Section instanceVariableNames: âquestions ...' classVariableNames: '' The thing is that #questions instance variable is a collection of Question AND QuestionGroup. They have polymorphic behavior, but they have not a common superclass (besides Object). How does my class model should look like? classModelForSection: aClassModel ... aClassModel newAttributeNamed: #questions collectionOf: ****?. Thanks for the help! Cheers, Alejandro
This is a question best suited to the Glorp mailing list (which I'm cc'ing in this email). What you need is an HorizontalTypeResolver, and define a common class as the ancestor for both of your classes. You'll have to define a descriptor for it, and you will use it to reference the "parent" of these (e.g. AbstractQuestion). So in your Glorp Descriptor you'll end up with something like: QuestionDescriptorSystem>>#typeResolverForAbstractQuestion ^(HorizontalTypeResolver forRootClass: AbstractQuestion) QuestionDescriptorSystem>>#descriptorForAbstractQuestion: aDescriptor "..." (self typeResolverFor: AbstractQuestion) register: aDescriptor abstract: true. QuestionDescriptorSystem>>#descriptorForQuestion: aDescriptor "..." (self typeResolverFor: AbstractQuestion) register: aDescriptor. QuestionDescriptorSystem>>#descriptorForQuestionGroup: aDescriptor "..." (self typeResolverFor: AbstractQuestion) register: aDescriptor. Then classModelForSection: aClassModel aClassModel newAttributeNamed: #questions collectionOf: AbstractQuestion I don't know about your model, but if both classes work polymorphically and have a common semantic root (it is "Question"), it is hard for me to see why they don't have a common ancestor. Disclaimer: the above code was written without testing it, based on my memory only :) Regards, Esteban A. Maringolo 2018-03-29 11:43 GMT-03:00 Alejandro Infante <alejandroinfante91@gmail.com>:
Hi guys!
Iâm trying to use GLORP and Iâm having problems defining the class model for a class which has an instance variable which is a collection of instances of two different classes:
I have 3 classes named: { Section . Question . QuestionGroup } and I have problems for specifying the glorp class model for Section. Object subclass: #Section instanceVariableNames: âquestions ...' classVariableNames: ''
The thing is that #questions instance variable is a collection of Question AND QuestionGroup. They have polymorphic behavior, but they have not a common superclass (besides Object).
How does my class model should look like?
classModelForSection: aClassModel ... aClassModel newAttributeNamed: #questions collectionOf: ****?.
Thanks for the help! Cheers, Alejandro
Thanks! I will try that. Alejandro
On Mar 29, 2018, at 2:47 PM, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
This is a question best suited to the Glorp mailing list (which I'm cc'ing in this email).
What you need is an HorizontalTypeResolver, and define a common class as the ancestor for both of your classes. You'll have to define a descriptor for it, and you will use it to reference the "parent" of these (e.g. AbstractQuestion).
So in your Glorp Descriptor you'll end up with something like:
QuestionDescriptorSystem>>#typeResolverForAbstractQuestion ^(HorizontalTypeResolver forRootClass: AbstractQuestion)
QuestionDescriptorSystem>>#descriptorForAbstractQuestion: aDescriptor "..." (self typeResolverFor: AbstractQuestion) register: aDescriptor abstract: true.
QuestionDescriptorSystem>>#descriptorForQuestion: aDescriptor "..." (self typeResolverFor: AbstractQuestion) register: aDescriptor.
QuestionDescriptorSystem>>#descriptorForQuestionGroup: aDescriptor "..." (self typeResolverFor: AbstractQuestion) register: aDescriptor.
Then classModelForSection: aClassModel aClassModel newAttributeNamed: #questions collectionOf: AbstractQuestion
I don't know about your model, but if both classes work polymorphically and have a common semantic root (it is "Question"), it is hard for me to see why they don't have a common ancestor.
Disclaimer: the above code was written without testing it, based on my memory only :)
Regards,
Esteban A. Maringolo
2018-03-29 11:43 GMT-03:00 Alejandro Infante <alejandroinfante91@gmail.com>:
Hi guys!
Iâm trying to use GLORP and Iâm having problems defining the class model for a class which has an instance variable which is a collection of instances of two different classes:
I have 3 classes named: { Section . Question . QuestionGroup } and I have problems for specifying the glorp class model for Section. Object subclass: #Section instanceVariableNames: âquestions ...' classVariableNames: ''
The thing is that #questions instance variable is a collection of Question AND QuestionGroup. They have polymorphic behavior, but they have not a common superclass (besides Object).
How does my class model should look like?
classModelForSection: aClassModel ... aClassModel newAttributeNamed: #questions collectionOf: ****?.
Thanks for the help! Cheers, Alejandro
participants (2)
-
Alejandro Infante -
Esteban A. Maringolo