Looking for multiple step delegations

8 views
Skip to first unread message

Georg Heeg

unread,
Feb 8, 2024, 10:29:04 AM2/8/24
to glorp-group

I want to create a pseudo variable in a glorp descriptor which generates nested joints.

Here are the example tables I have created:

1.       Person

a.       primaryKey (Integer)

b.       firstName (String)

c.       lastName (String

d.       company (Integer, foreign reference to Company)

2.       Company

a.       primaryKey (Integer)

b.       companyName (String)

c.       address (Integer, foreign reference to Address)

3.       Address

a.       primaryKey (Integer)

b.       postcode (String)

c.       city (String)

d.       street (String)

Certainly I can write the query

session read: Person where: [:person | person company postCode = '44227']

This query is translated to SQL

'SELECT t1.primaryKey, t1.firstName, t1.lastName, t1.company
FROM ((person t1 INNER JOIN company t2 ON (t1.company = t2.primaryKey)) INNER JOIN address t3 ON (t2.address = t3.primaryKey))
WHERE (t3.postCode = :1)ByteString'

I was able to create a pseudo variable postCode in Company by adding the following code to the descriptor:

addressTable := self tableNamed: 'address'.
(aDescriptor directToOneMapping)
attributeName: #postCode referenceClass: String;
resultField: (addressTable
fieldNamed: 'postCode');
join: (Join from: (table fieldNamed: 'address')
to: (addressTable fieldNamed: 'primaryKey'));
beForPseudoVariable

Now I rewrite the query to

session read: Person where: [:person | person company postCode = '44227']

And the SQL code Glorp creates is exactly the same.

But I want more: I want to be able to write

session read: Person where: [:person | person postCode = '44227']

I tried a lot if different ideas including blocks for the join, but nothings works so for.

Does anybody have an idea how to write the pseudo variable descriptor?

Reply all
Reply to author
Forward
0 new messages