Glorp fundamental understanding issues

22 views
Skip to first unread message

Sanjay Minni

unread,
Oct 30, 2023, 1:27:49 AM10/30/23
to glorp-group
Hi 
i have some basic questions on Glorp as the variations in the examples have left me confused 

a. what is the difference between newMapping: and addMapping:

b. when is a classModel not required / or required

c. Descriptor entries / how to map Same Object twice i.e. 2 FKs from 1 table to another table.   
e.g.     (here a EMERGENCY_COORDINATOR are regular TEACHERs also)
Teacher (Object & table)           Classroom(object & Table)
=========================          ========================= 
  ID                                   CLASSROOM     
  NAME                 <= (TeacherID)  CLASSTEACHER
                       <= (TeacherID)  EMERGENCY_COORDINATOR

jtuchel

unread,
Oct 31, 2023, 9:30:16 AM10/31/23
to glorp-group
Sanjay,

re a) looking at the code, there is not much of a difference. One requires you to provide amn instance, the other wants the Class of the mapping. There is an additional check in addMapping: that's not in newMapping: , but that's it. Out of my head, I couldn't tell you which one I use.

re b) I never asked myself this question. My take is that it helps to check plauisbilities and also auto-determine the mappings for foreign keys etc. I see little reason why it would be absolutely necessary, and I always implement it. Maybe it's a waste of time, I dunno. I am too busy solving hard Glorp problems to even wonder ;-)

c) is the only one of your questions I think I can help answer. You can provide two different each with a JOIN that makes the relation between the tables explicit.

(aDescriptor newMapping: OneToOneMapping)
attributeName: #emergencyCoodinator;
referenceClass: Teacher;
mappingCriteria: (Join
from: (table fieldNamed: 'EMERGENCY_COORDINATOR')
to: ((self tableNamed: 'Teacher') fieldNamed: 'ID'))).

(aDescriptor newMapping: OneToOneMapping)
attributeName: #classTeacher;
referenceClass: Teacher;
mappingCriteria: (Join
from: (table fieldNamed: 'CLASSTEACHER
to: ((self tableNamed: 'Teacher') fieldNamed: 'ID')))


HTH

Joachim

Sanjay Minni

unread,
Oct 31, 2023, 12:40:17 PM10/31/23
to glorp-group
Thanks Joachim,  item c) of my mail was the most important anyway
it seems to be working with your code (i am yet to test extensively in full functions). 

However there are some things I don't understand
i get a debugger walkback when i define FK in the corresponding descriptor tableFor definition (though i have the FK directly defined in the database)
        ...  
        aTable addForeignKeyFrom: CLASSTEACHER  to: ((self tableNamed: 'Teacher') fieldNamed: 'id').
aTable addForeignKeyFrom: EMERGENCY_COORDINATOR to: ((self tableNamed: 'Teacher') fieldNamed: 'id').
Debugger error: Instance of MyDescriptor did not understand #inflector, but it accepts any one of the two lines above (not both together)

regarding a) & b) what i found in the code was that 
newMapping: - to use if a classModel defined & 
addMapping: to use if no classModel is defined   
I will also go your way i.e. define classModel as clarity is easier to read over brevity. Ok you do save some redundancy if no classModel is defined and the code is shifted to the descriptor for the class instead 

Somehow i feel Glorp has too many variations / helper methods and the examples seem like a demonstration in code variation. I find it difficult to wrap my head around.
pls see if you can help with some inputs on the Table FK issue above

thanks
Sanjay
 

Alan Knight

unread,
Oct 31, 2023, 3:15:22 PM10/31/23
to glorp...@googlegroups.com
newMapping: is preferred, there's stuff it can fill in automatically when creating the new mapping that otherwise has to be done manually.
The class model lets you define the types and fields once rather than as part of the mapping, so it's nice to have. That's probably part of what newMapping: relies on.
inflector sounds like it's using one of the example systems that tried to do Ruby on Rails kinds of things, assuming what it can do to recognize/form plurals, etc. Since then I've done a lot of work in internationalization and that seems like a bad idea.
I'd say you're right that there are too many variations, and too many different things that were changed (like introducing class and table models) but not everything is switched to use them.


--
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 glorp-group...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/dd175e14-5401-4ca2-9e13-06932791ab1bn%40googlegroups.com.

Todd Blanchard

unread,
Oct 31, 2023, 3:19:11 PM10/31/23
to glorp...@googlegroups.com
I added inflector to pharo's port along with the active record descriptor system to work with existing databases conforming to Ruby on Rails.  If you are starting from scratch, I would set the inflector up to do nothing (there are options for this).


jtuchel

unread,
Oct 31, 2023, 4:00:22 PM10/31/23
to glorp-group
Hi Sanjay,

my VAST image has no senders or implementors if #inflector, so I am afraid I can't help you there. What Smalltalk (doialect and version) are you on?

Is the code you copied here from an actual image? What kinds of variables are CLASSTEACHER and EMERGENCY_COORDINATOR and what do they hold? Seems like you are storing fields in global variables... Is this some ActiveRecord magic stuff?

Joachim

Sanjay Minni

unread,
Nov 1, 2023, 2:48:04 AM11/1/23
to glorp...@googlegroups.com
Hi Todd,
(I am using Pharo 11)

I am subclassing from DescriptorSystem
while creating the session initially only I get a walkback in the method below - (error: inflector not found)

>>joinFor: aMapping toTables: toTables fromConstraints: fromConstraints toConstraints: toConstraints 
   ...
   prefix := (self inflector underscore: aMapping attributeName) copyUpTo: $_.

on a search it seems #inflector is used at various places but cant figure how many will be encountered in the DescriptorSystem hierarchy
so could you take a look if it can be fixed

Sanjay

Sanjay Minni

unread,
Nov 1, 2023, 2:55:26 AM11/1/23
to glorp...@googlegroups.com
Hi Joachim,

I am using Pharo 11

Todd is on this group, per his mail - he had introduced #inflector in the pharo port - so requesting him to take a look
I am subclassing directly from DescriptorSystem - not using ActiveRecordStuff. The Caps were just code i had typed as an example to illustrate, forgetting that Caps can be confused to mean Globals. Dont worry - It's not actual code. :) - I am a long way from that Guru stage of Nirvana where I will dare play with Globals

Sanjay   

--
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 glorp-group...@googlegroups.com.

Todd Blanchard

unread,
Nov 1, 2023, 4:43:35 PM11/1/23
to glorp...@googlegroups.com
How long ago did you pull glorp from git because I think astares did a bunch of fixes very recently.

If you're up to date, or you update and it remains an issue, I will dig in this afternoon.  Let me know.

Todd Blanchard

unread,
Nov 1, 2023, 6:59:07 PM11/1/23
to glorp...@googlegroups.com

Sanjay Minni

unread,
Nov 1, 2023, 10:49:42 PM11/1/23
to glorp...@googlegroups.com
Its up-to-date , thanks for taking it up

Reply all
Reply to author
Forward
0 new messages