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 <[hidden email]> 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 <[hidden email]>: >> 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 > |
Free forum by Nabble | Edit this page |