Re: [Pharo-users] Question about GLORP class models

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] Question about GLORP class models

Esteban A. Maringolo
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

--
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 https://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.