Webvelocity/Glorp question (WV 1.0)

Skip to first unread message


Sep 7, 2010, 3:02:17 AM9/7/10
to WebVelocity
Trying to create two foreign keys between two tables by something like

tableForAaS: aTable
| b1_id b2_id|
(aTable createFieldNamed: 'id' type: platform serial) bePrimaryKey.
b1_id := (aTable createFieldNamed: 'b1_id' type: platform integer) .
b2_id := (aTable createFieldNamed: 'b2_id' type: platform integer) .
aTable addForeignKeyFrom: b1_id to: ((self tableNamed: 'BbS')
fieldNamed: 'id').
aTable addForeignKeyFrom: b2_id toTable: (self tableNamed: 'BbS')
tableForBbS: aTable
(aTable createFieldNamed: 'id' type: platform serial) bePrimaryKey.
(aTable createFieldNamed: 'nr' type: platform integer) beNullable:

I get the error message:
Cannot calculate the join automatically, not enough information

There is no problem defiining only one foreign key, of course.

What can I do?


Alan Knight

Sep 7, 2010, 9:33:43 AM9/7/10
to WebVelocity
The message means exactly what it says, but it's referring to the descriptor part, not the table part.

When you define a relationship from an Aa to a Bb, then normally you don't have to say much at all. Glorp will do its best to figure out the types, and based on the types, what foreign key relationships are involved. But if there's more than one foreign key from the Aa table to the Bb table, then it doesn't know which one to use. So you have to define the relationship more explicitly, so in

descriptorForAa: aDescriptor
      relationship1 := aDescriptor oneToOneMapping
           attributeName: #one;
        join: (Join from: b1_id to: ((self tableNamed: 'BbS')
fieldNamed: 'id')).

and similarly for relationship2. Actually, you might even get away with just doing it for one, and it might be smart enough to look for the potential foreign key that isn't already used. But I'm not sure about that.
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to webve...@googlegroups.com.
To unsubscribe from this group, send email to webvelocity...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

Alan Knight [|], Engineering Manager, Cincom Smalltalk
Reply all
Reply to author
0 new messages