ManyToManyMappings with link table

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

ManyToManyMappings with link table

Esteban A. Maringolo
Hi,

I defined a ManyToMany mapping between objects of Group and User using an intermediate table. 
It is, in the Smalltalk side an instance of Group has a collection holding instances of Users.

The first time I save the group its users are saved to the intermediate table.

But if I add another user or try to save the Group again, I get a PK violation in the link table, because it is trying to save the users again.

I know I could reify the relation as an object itself, but I thought the ManyToMany relation was meant to avoid this.

What can I do to avoid that?
(other than manually deleting the ROWS from the table).

Regards!

Esteban.

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

ManyToManyMappings with link table

Alan Knight
That should work fine, and there are numerous examples in the tests that do that. So probably the problem is that there's something wrong in the descriptor or in the table definition. Which I know is not the most helpful. But I'd say look at the way things are set up in the tests and see if you can see something different. If you're getting the PK violation from the database, it would make me suspicious you haven't told Glorp that both link fields in the link table are treated as primary keys. If you're getting it in Glorp I'd be suspicious that you might have different objects with the same primary keys, i.e. copies from somewhere.

On Mon Apr 28 2014 at 11:37:00 AM, Esteban A. Maringolo <[hidden email]> wrote:
Hi,

I defined a ManyToMany mapping between objects of Group and User using an intermediate table. 
It is, in the Smalltalk side an instance of Group has a collection holding instances of Users.

The first time I save the group its users are saved to the intermediate table.

But if I add another user or try to save the Group again, I get a PK violation in the link table, because it is trying to save the users again.

I know I could reify the relation as an object itself, but I thought the ManyToMany relation was meant to avoid this.

What can I do to avoid that?
(other than manually deleting the ROWS from the table).

Regards!

Esteban.

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

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToManyMappings with link table

Esteban A. Maringolo
I looked at the test examples and found nothing different. I even tried specifying the Join explicitely.
"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

I have the table EXPO and the table PERSONA, both having their corresponding ID fields.

descriptorForTsExpo: aDescriptor
| table linkTable |
table := self tableNamed: 'EXPO'.
aDescriptor table: table.
self addNamedModelMappingsTo: aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #startDate to: (table fieldNamed: 'startDate').
(aDescriptor newMapping: DirectMapping) from: #endDate to: (table fieldNamed: 'endDate').
linkTable := self tableNamed: 'EXPO_ON_PERSONA'.
(aDescriptor newMapping: ManyToManyMapping)
attributeName: #personas;
referenceClass: TsPersona;
join: (Join
from: (table fieldNamed: 'id')
to: (linkTable fieldNamed: 'persona_id')) "With or without the join is the same".

classModelForTsExpo: aClassModel
self addNamedModelAttributesTo: aClassModel.
aClassModel newAttributeNamed: #startDate.
aClassModel newAttributeNamed: #endDate.
aClassModel newAttributeNamed: #personas collectionOf: TsPersona.



tableForEXPO_ON_PERSONA: aTable
| expoKey personaKey |
expoKey := aTable createFieldNamed: 'expo_id' type: (platform int4).
aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO') fieldNamed: 'id').

personaKey := aTable createFieldNamed: 'persona_id' type: (platform int4).
aTable addForeignKeyFrom: personaKey  to: ((self tableNamed: 'PERSONA') fieldNamed: 'id').

expoKey bePrimaryKey.
personaKey bePrimaryKey.


Do you see anything particularly wrong here?
I played game of differences against the ManyToMany tests, but couldn't discern what is missing in my code.

I found an example using 
#polymorphicJoinToItemFromField: aField
"Return a polymorphic join to the GlorpInventoryItem subclasses from the given field."

My TsPersona class is an abstract class, but I also tried with non-abstract (it is, no type resolvers) classes, and I got the same error.




Regards!

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: ManyToManyMappings with link table

Verleysen, Dirk

Are you sure you’re updating the same objects that you read from the database ?

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban A. Maringolo
Sent: maandag 28 april 2014 23:05
To: [hidden email]
Subject: Re: ManyToManyMappings with link table

 

I looked at the test examples and found nothing different. I even tried specifying the Join explicitely.

"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

 

I have the table EXPO and the table PERSONA, both having their corresponding ID fields.

 

descriptorForTsExpo: aDescriptor

            | table linkTable |

            table := self tableNamed: 'EXPO'.

            aDescriptor table: table.

            self addNamedModelMappingsTo: aDescriptor table: table.

            (aDescriptor newMapping: DirectMapping) from: #startDate to: (table fieldNamed: 'startDate').    

            (aDescriptor newMapping: DirectMapping) from: #endDate to: (table fieldNamed: 'endDate').

            linkTable := self tableNamed: 'EXPO_ON_PERSONA'.

            (aDescriptor newMapping: ManyToManyMapping)

                        attributeName: #personas;

                        referenceClass: TsPersona;

                        join: (Join

                                               from: (table fieldNamed: 'id')

                                               to: (linkTable fieldNamed: 'persona_id')) "With or without the join is the same".

 

classModelForTsExpo: aClassModel

            self addNamedModelAttributesTo: aClassModel.

            aClassModel newAttributeNamed: #startDate.

            aClassModel newAttributeNamed: #endDate.

            aClassModel newAttributeNamed: #personas collectionOf: TsPersona.

 

 

 

tableForEXPO_ON_PERSONA: aTable

            | expoKey personaKey |

            expoKey := aTable createFieldNamed: 'expo_id' type: (platform int4).

            aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO') fieldNamed: 'id').

 

            personaKey := aTable createFieldNamed: 'persona_id' type: (platform int4).

            aTable addForeignKeyFrom: personaKey  to: ((self tableNamed: 'PERSONA') fieldNamed: 'id').

 

            expoKey bePrimaryKey.

            personaKey bePrimaryKey.



Do you see anything particularly wrong here?

I played game of differences against the ManyToMany tests, but couldn't discern what is missing in my code.

 

I found an example using 

#polymorphicJoinToItemFromField: aField

            "Return a polymorphic join to the GlorpInventoryItem subclasses from the given field."

 

My TsPersona class is an abstract class, but I also tried with non-abstract (it is, no type resolvers) classes, and I got the same error.

 

 

 

 

Regards!

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

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: ManyToManyMappings with link table

Alan Knight
Yes, I would check that. When you get the primary key conflict you should be able to find the two rows that cause the problem in the debugger, and each should have an owner. In the case of the link table the owner is a RowMapKey. In the case of the others it's the object. 

On Mon Apr 28 2014 at 2:13:06 PM, Verleysen, Dirk <[hidden email]> wrote:

Are you sure you’re updating the same objects that you read from the database ?

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban A. Maringolo
Sent: maandag 28 april 2014 23:05
To: [hidden email]
Subject: Re: ManyToManyMappings with link table

 

I looked at the test examples and found nothing different. I even tried specifying the Join explicitely.

"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

 

I have the table EXPO and the table PERSONA, both having their corresponding ID fields.

 

descriptorForTsExpo: aDescriptor

            | table linkTable |

            table := self tableNamed: 'EXPO'.

            aDescriptor table: table.

            self addNamedModelMappingsTo: aDescriptor table: table.

            (aDescriptor newMapping: DirectMapping) from: #startDate to: (table fieldNamed: 'startDate').    

            (aDescriptor newMapping: DirectMapping) from: #endDate to: (table fieldNamed: 'endDate').

            linkTable := self tableNamed: 'EXPO_ON_PERSONA'.

            (aDescriptor newMapping: ManyToManyMapping)

                        attributeName: #personas;

                        referenceClass: TsPersona;

                        join: (Join

                                               from: (table fieldNamed: 'id')

                                               to: (linkTable fieldNamed: 'persona_id')) "With or without the join is the same".

 

classModelForTsExpo: aClassModel

            self addNamedModelAttributesTo: aClassModel.

            aClassModel newAttributeNamed: #startDate.

            aClassModel newAttributeNamed: #endDate.

            aClassModel newAttributeNamed: #personas collectionOf: TsPersona.

 

 

 

tableForEXPO_ON_PERSONA: aTable

            | expoKey personaKey |

            expoKey := aTable createFieldNamed: 'expo_id' type: (platform int4).

            aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO') fieldNamed: 'id').

 

            personaKey := aTable createFieldNamed: 'persona_id' type: (platform int4).

            aTable addForeignKeyFrom: personaKey  to: ((self tableNamed: 'PERSONA') fieldNamed: 'id').

 

            expoKey bePrimaryKey.

            personaKey bePrimaryKey.



Do you see anything particularly wrong here?

I played game of differences against the ManyToMany tests, but couldn't discern what is missing in my code.

 

I found an example using 

#polymorphicJoinToItemFromField: aField

            "Return a polymorphic join to the GlorpInventoryItem subclasses from the given field."

 

My TsPersona class is an abstract class, but I also tried with non-abstract (it is, no type resolvers) classes, and I got the same error.

 

 

 

 

Regards!

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

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

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: ManyToManyMappings with link table

Wallen, David
In reply to this post by Verleysen, Dirk

You could also have a look at the GlorpGuide pdf. There’s a companion example that may be somewhat similar to your example, called MyAppDescriptorSystem (GlorpGuide.pcl)

- Dave

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Verleysen, Dirk
Sent: Monday, April 28, 2014 2:13 PM
To: [hidden email]
Subject: RE: ManyToManyMappings with link table

 

Are you sure you’re updating the same objects that you read from the database ?

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban A. Maringolo
Sent: maandag 28 april 2014 23:05
To: [hidden email]
Subject: Re: ManyToManyMappings with link table

 

I looked at the test examples and found nothing different. I even tried specifying the Join explicitely.

"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

 

I have the table EXPO and the table PERSONA, both having their corresponding ID fields.

 

descriptorForTsExpo: aDescriptor

            | table linkTable |

            table := self tableNamed: 'EXPO'.

            aDescriptor table: table.

            self addNamedModelMappingsTo: aDescriptor table: table.

            (aDescriptor newMapping: DirectMapping) from: #startDate to: (table fieldNamed: 'startDate').    

            (aDescriptor newMapping: DirectMapping) from: #endDate to: (table fieldNamed: 'endDate').

            linkTable := self tableNamed: 'EXPO_ON_PERSONA'.

            (aDescriptor newMapping: ManyToManyMapping)

                        attributeName: #personas;

                        referenceClass: TsPersona;

                        join: (Join

                                               from: (table fieldNamed: 'id')

                                               to: (linkTable fieldNamed: 'persona_id')) "With or without the join is the same".

 

classModelForTsExpo: aClassModel

            self addNamedModelAttributesTo: aClassModel.

            aClassModel newAttributeNamed: #startDate.

            aClassModel newAttributeNamed: #endDate.

            aClassModel newAttributeNamed: #personas collectionOf: TsPersona.

 

 

 

tableForEXPO_ON_PERSONA: aTable

            | expoKey personaKey |

            expoKey := aTable createFieldNamed: 'expo_id' type: (platform int4).

            aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO') fieldNamed: 'id').

 

            personaKey := aTable createFieldNamed: 'persona_id' type: (platform int4).

            aTable addForeignKeyFrom: personaKey  to: ((self tableNamed: 'PERSONA') fieldNamed: 'id').

 

            expoKey bePrimaryKey.

            personaKey bePrimaryKey.



Do you see anything particularly wrong here?

I played game of differences against the ManyToMany tests, but couldn't discern what is missing in my code.

 

I found an example using 

#polymorphicJoinToItemFromField: aField

            "Return a polymorphic join to the GlorpInventoryItem subclasses from the given field."

 

My TsPersona class is an abstract class, but I also tried with non-abstract (it is, no type resolvers) classes, and I got the same error.

 

 

 

 

Regards!

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

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

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToManyMappings with link table

Esteban A. Maringolo
In reply to this post by Verleysen, Dirk
Yes, it is exactly the same instance. 

I run this in the workspace (there is only one TsPersona and TsExpo in the DB):

expo := (glorpSession read: TsExpo) anyOne.
persona := (glorpSession read: TsPersona) anyOne.

expo personas isEmpty "true".
expo personas add: persona.
system save: expo. "ok"
"INSERT INTO EXPO_ON_PERSONA (expo_id,persona_id)  VALUES (1,1); (0.0 s)"

"Attempt to save again THE SAME INSTANCE."

system save: expo.
"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

"Afterwards I attempted to test what happens if I REMOVE the elements from the array."
expo personas removeAll. "ok"
expo personas isEmpty "true".
system save: expo. "seems fine"
expo personas isEmpty "true".

glorpSession reset.
(glorpSession read: TsExpo) anyOne personas isEmpty. "false"

"The personas where never removed from the link table"

Maybe everything should run in the context of a UnitOfWork, but I don't see why exactly.

El lunes, 28 de abril de 2014 18:12:41 UTC-3, Verleysen, Dirk escribió:

Are you sure you’re updating the same objects that you read from the database ?

 

From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OyI5W1vAKTYJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">glorp...@... [mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OyI5W1vAKTYJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">glorp...@googlegroups.com] On Behalf Of Esteban A. Maringolo
Sent: maandag 28 april 2014 23:05
To: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OyI5W1vAKTYJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">glorp...@...
Subject: Re: ManyToManyMappings with link table

 

I looked at the test examples and found nothing different. I even tried specifying the Join explicitely.

"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

 

I have the table EXPO and the table PERSONA, both having their corresponding ID fields.

 

descriptorForTsExpo: aDescriptor

            | table linkTable |

            table := self tableNamed: 'EXPO'.

            aDescriptor table: table.

            self addNamedModelMappingsTo: aDescriptor table: table.

            (aDescriptor newMapping: DirectMapping) from: #startDate to: (table fieldNamed: 'startDate').    

            (aDescriptor newMapping: DirectMapping) from: #endDate to: (table fieldNamed: 'endDate').

            linkTable := self tableNamed: 'EXPO_ON_PERSONA'.

            (aDescriptor newMapping: ManyToManyMapping)

                        attributeName: #personas;

                        referenceClass: TsPersona;

                        join: (Join

                                               from: (table fieldNamed: 'id')

                                               to: (linkTable fieldNamed: 'persona_id')) "With or without the join is the same".

 

classModelForTsExpo: aClassModel

            self addNamedModelAttributesTo: aClassModel.

            aClassModel newAttributeNamed: #startDate.

            aClassModel newAttributeNamed: #endDate.

            aClassModel newAttributeNamed: #personas collectionOf: TsPersona.

 

 

 

tableForEXPO_ON_PERSONA: aTable

            | expoKey personaKey |

            expoKey := aTable createFieldNamed: 'expo_id' type: (platform int4).

            aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO') fieldNamed: 'id').

 

            personaKey := aTable createFieldNamed: 'persona_id' type: (platform int4).

            aTable addForeignKeyFrom: personaKey  to: ((self tableNamed: 'PERSONA') fieldNamed: 'id').

 

            expoKey bePrimaryKey.

            personaKey bePrimaryKey.



Do you see anything particularly wrong here?

I played game of differences against the ManyToMany tests, but couldn't discern what is missing in my code.

 

I found an example using 

#polymorphicJoinToItemFromField: aField

            "Return a polymorphic join to the GlorpInventoryItem subclasses from the given field."

 

My TsPersona class is an abstract class, but I also tried with non-abstract (it is, no type resolvers) classes, and I got the same error.

 

 

 

 

Regards!

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OyI5W1vAKTYJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">glorp-group...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OyI5W1vAKTYJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;"> glorp...@....
Visit this group at <a href="http://groups.google.com/group/glorp-group" target="_blank" onmousedown="this.href='http://groups.google.com/group/glorp-group';return true;" onclick="this.href='http://groups.google.com/group/glorp-group';return true;">http://groups.google.com/group/glorp-group.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToManyMappings with link table

Alan Knight
What is #save: on a descriptor system? I don't see that in Glorp sources. There's one on session, but I think it's a bad idea to use it. It looks like it's trying to force the session to treat an object as new. Which would make it unsurprising if you got a primary key conflict.

Try session modify: expo in: [ expo personas add: persona].
or just 
  session transact: [
     session register: expo.
     expo personas add: persona].

Glorp is transaction-based, and does not like trying to save individual objects.

On Mon Apr 28 2014 at 3:27:31 PM, Esteban A. Maringolo <[hidden email]> wrote:
Yes, it is exactly the same instance. 

I run this in the workspace (there is only one TsPersona and TsExpo in the DB):

expo := (glorpSession read: TsExpo) anyOne.
persona := (glorpSession read: TsPersona) anyOne.

expo personas isEmpty "true".
expo personas add: persona.
system save: expo. "ok"
"INSERT INTO EXPO_ON_PERSONA (expo_id,persona_id)  VALUES (1,1); (0.0 s)"

"Attempt to save again THE SAME INSTANCE."

system save: expo.
"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

"Afterwards I attempted to test what happens if I REMOVE the elements from the array."
expo personas removeAll. "ok"
expo personas isEmpty "true".
system save: expo. "seems fine"
expo personas isEmpty "true".

glorpSession reset.
(glorpSession read: TsExpo) anyOne personas isEmpty. "false"

"The personas where never removed from the link table"

Maybe everything should run in the context of a UnitOfWork, but I don't see why exactly.

El lunes, 28 de abril de 2014 18:12:41 UTC-3, Verleysen, Dirk escribió:

Are you sure you’re updating the same objects that you read from the database ?

 

From: [hidden email] [mailto:glorp...@googlegroups.com] On Behalf Of Esteban A. Maringolo


Sent: maandag 28 april 2014 23:05


Subject: Re: ManyToManyMappings with link table

 

I looked at the test examples and found nothing different. I even tried specifying the Join explicitely.

"GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique constraint.."

 

I have the table EXPO and the table PERSONA, both having their corresponding ID fields.

 

descriptorForTsExpo: aDescriptor

            | table linkTable |

            table := self tableNamed: 'EXPO'.

            aDescriptor table: table.

            self addNamedModelMappingsTo: aDescriptor table: table.

            (aDescriptor newMapping: DirectMapping) from: #startDate to: (table fieldNamed: 'startDate').    

            (aDescriptor newMapping: DirectMapping) from: #endDate to: (table fieldNamed: 'endDate').

            linkTable := self tableNamed: 'EXPO_ON_PERSONA'.

            (aDescriptor newMapping: ManyToManyMapping)

                        attributeName: #personas;

                        referenceClass: TsPersona;

                        join: (Join

                                               from: (table fieldNamed: 'id')

                                               to: (linkTable fieldNamed: 'persona_id')) "With or without the join is the same".

 

classModelForTsExpo: aClassModel

            self addNamedModelAttributesTo: aClassModel.

            aClassModel newAttributeNamed: #startDate.

            aClassModel newAttributeNamed: #endDate.

            aClassModel newAttributeNamed: #personas collectionOf: TsPersona.

 

 

 

tableForEXPO_ON_PERSONA: aTable

            | expoKey personaKey |

            expoKey := aTable createFieldNamed: 'expo_id' type: (platform int4).

            aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO') fieldNamed: 'id').

 

            personaKey := aTable createFieldNamed: 'persona_id' type: (platform int4).

            aTable addForeignKeyFrom: personaKey  to: ((self tableNamed: 'PERSONA') fieldNamed: 'id').

 

            expoKey bePrimaryKey.

            personaKey bePrimaryKey.



Do you see anything particularly wrong here?

I played game of differences against the ManyToMany tests, but couldn't discern what is missing in my code.

 

I found an example using 

#polymorphicJoinToItemFromField: aField

            "Return a polymorphic join to the GlorpInventoryItem subclasses from the given field."

 

My TsPersona class is an abstract class, but I also tried with non-abstract (it is, no type resolvers) classes, and I got the same error.

 

 

 

 

Regards!

--
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 post to this group, send email to [hidden email].

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

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToManyMappings with link table

Esteban A. Maringolo
Sorry, the system variable isn't a DescriptorSystem, it is the entry
point to my system (TsSystem), and forwards messages such as #save: to
its underlying glorpDatabase.

The #transact: option didn't work, same error as before; however I
changed all the statements to work inside a unit of work and it
worked. I also modified some variable names for clarification:

glorpSession inUnitOfWorkDo: [
| expo persona |
expo := (glorpSession read: TsExpo) anyOne.
persona := (glorpSession read: TsPersona) anyOne.
expo personas isEmpty "true".
expo personas add: persona.
glorpSession register: expo  ].

"INSERT INTO EXPO_ON_PERSONA (expo_id,persona_id)  VALUES (1,1)
(0.0 s)"

glorpSession inUnitOfWorkDo: [
| expo |
expo := (glorpSession read: TsExpo) anyOne.
glorpSession save: expo ]. "nothing happens. ok."

glorpSession inUnitOfWorkDo: [
| expo |
expo := (glorpSession read: TsExpo) anyOne.
expo personas removeAll. "ok"
expo personas isEmpty "true".
glorpSession register: expo ].

glorpSession inUnitOfWorkDo: [
| expo |
expo := (glorpSession read: TsExpo) anyOne.
expo personas isEmpty "true".
].

So far. It works.


What puzzles me, is why if the cache is at the GlorpSession level do I
have to make these modifications inside a unit of work. Maybe the
option to no use units of work at all is too optimistic/allowing,
working only in some cases.

Now I'll have to twist my head around on how to adapt what I already
have to make it work in the context of a web app (where I can't have a
long running unit of work :))

Thanks for the support.

Esteban A. Maringolo


2014-04-28 19:35 GMT-03:00 Alan Knight <[hidden email]>:

> What is #save: on a descriptor system? I don't see that in Glorp sources.
> There's one on session, but I think it's a bad idea to use it. It looks like
> it's trying to force the session to treat an object as new. Which would make
> it unsurprising if you got a primary key conflict.
>
> Try session modify: expo in: [ expo personas add: persona].
> or just
>   session transact: [
>      session register: expo.
>      expo personas add: persona].
>
> Glorp is transaction-based, and does not like trying to save individual
> objects.
>
> On Mon Apr 28 2014 at 3:27:31 PM, Esteban A. Maringolo
> <[hidden email]> wrote:
>>
>> Yes, it is exactly the same instance.
>>
>> I run this in the workspace (there is only one TsPersona and TsExpo in the
>> DB):
>>
>> expo := (glorpSession read: TsExpo) anyOne.
>> persona := (glorpSession read: TsPersona) anyOne.
>>
>> expo personas isEmpty "true".
>> expo personas add: persona.
>> system save: expo. "ok"
>> "INSERT INTO EXPO_ON_PERSONA (expo_id,persona_id)  VALUES (1,1); (0.0 s)"
>>
>> "Attempt to save again THE SAME INSTANCE."
>>
>> system save: expo.
>> "GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique
>> constraint.."
>>
>> "Afterwards I attempted to test what happens if I REMOVE the elements from
>> the array."
>> expo personas removeAll. "ok"
>> expo personas isEmpty "true".
>> system save: expo. "seems fine"
>> expo personas isEmpty "true".
>>
>> glorpSession reset.
>> (glorpSession read: TsExpo) anyOne personas isEmpty. "false"
>>
>> "The personas where never removed from the link table"
>>
>> Maybe everything should run in the context of a UnitOfWork, but I don't
>> see why exactly.
>>
>> El lunes, 28 de abril de 2014 18:12:41 UTC-3, Verleysen, Dirk escribió:
>>>
>>> Are you sure you’re updating the same objects that you read from the
>>> database ?
>>>
>>>
>>>
>>> From: [hidden email] [mailto:[hidden email]] On
>>> Behalf Of Esteban A. Maringolo
>>>
>>>
>>> Sent: maandag 28 april 2014 23:05
>>>
>>> To: [hidden email]
>>>
>>>
>>> Subject: Re: ManyToManyMappings with link table
>>>
>>>
>>>
>>> I looked at the test examples and found nothing different. I even tried
>>> specifying the Join explicitely.
>>>
>>> "GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique
>>> constraint.."
>>>
>>>
>>>
>>> I have the table EXPO and the table PERSONA, both having their
>>> corresponding ID fields.
>>>
>>>
>>>
>>> descriptorForTsExpo: aDescriptor
>>>
>>>             | table linkTable |
>>>
>>>             table := self tableNamed: 'EXPO'.
>>>
>>>             aDescriptor table: table.
>>>
>>>             self addNamedModelMappingsTo: aDescriptor table: table.
>>>
>>>             (aDescriptor newMapping: DirectMapping) from: #startDate to:
>>> (table fieldNamed: 'startDate').
>>>
>>>             (aDescriptor newMapping: DirectMapping) from: #endDate to:
>>> (table fieldNamed: 'endDate').
>>>
>>>             linkTable := self tableNamed: 'EXPO_ON_PERSONA'.
>>>
>>>             (aDescriptor newMapping: ManyToManyMapping)
>>>
>>>                         attributeName: #personas;
>>>
>>>                         referenceClass: TsPersona;
>>>
>>>                         join: (Join
>>>
>>>                                                from: (table fieldNamed:
>>> 'id')
>>>
>>>                                                to: (linkTable fieldNamed:
>>> 'persona_id')) "With or without the join is the same".
>>>
>>>
>>>
>>> classModelForTsExpo: aClassModel
>>>
>>>             self addNamedModelAttributesTo: aClassModel.
>>>
>>>             aClassModel newAttributeNamed: #startDate.
>>>
>>>             aClassModel newAttributeNamed: #endDate.
>>>
>>>             aClassModel newAttributeNamed: #personas collectionOf:
>>> TsPersona.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> tableForEXPO_ON_PERSONA: aTable
>>>
>>>             | expoKey personaKey |
>>>
>>>             expoKey := aTable createFieldNamed: 'expo_id' type: (platform
>>> int4).
>>>
>>>             aTable addForeignKeyFrom: expoKey to: ((self tableNamed:
>>> 'EXPO') fieldNamed: 'id').
>>>
>>>
>>>
>>>             personaKey := aTable createFieldNamed: 'persona_id' type:
>>> (platform int4).
>>>
>>>             aTable addForeignKeyFrom: personaKey  to: ((self tableNamed:
>>> 'PERSONA') fieldNamed: 'id').
>>>
>>>
>>>
>>>             expoKey bePrimaryKey.
>>>
>>>             personaKey bePrimaryKey.
>>>
>>>
>>>
>>> Do you see anything particularly wrong here?
>>>
>>> I played game of differences against the ManyToMany tests, but couldn't
>>> discern what is missing in my code.
>>>
>>>
>>>
>>> I found an example using
>>>
>>> #polymorphicJoinToItemFromField: aField
>>>
>>>             "Return a polymorphic join to the GlorpInventoryItem
>>> subclasses from the given field."
>>>
>>>
>>>
>>> My TsPersona class is an abstract class, but I also tried with
>>> non-abstract (it is, no type resolvers) classes, and I got the same error.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Regards!
>>>
>>> --
>>> 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 http://groups.google.com/group/glorp-group.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> 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 http://groups.google.com/group/glorp-group.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "glorp-group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/glorp-group/fxkjLVld2AE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToManyMappings with link table

Esteban A. Maringolo
In reply to this post by Wallen, David
David,

I'm using Pharo port of GLORP, do you have a link to the
GlorpGuide.pdf, I couldn't find it online.

Best regards,

Esteban A. Maringolo


2014-04-28 19:21 GMT-03:00 Wallen, David <[hidden email]>:

> You could also have a look at the GlorpGuide pdf. There’s a companion
> example that may be somewhat similar to your example, called
> MyAppDescriptorSystem (GlorpGuide.pcl)
>
> - Dave
>
>
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Verleysen, Dirk
> Sent: Monday, April 28, 2014 2:13 PM
> To: [hidden email]
> Subject: RE: ManyToManyMappings with link table
>
>
>
> Are you sure you’re updating the same objects that you read from the
> database ?
>
>
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Esteban A. Maringolo
> Sent: maandag 28 april 2014 23:05
> To: [hidden email]
> Subject: Re: ManyToManyMappings with link table
>
>
>
> I looked at the test examples and found nothing different. I even tried
> specifying the Join explicitely.
>
> "GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique
> constraint.."
>
>
>
> I have the table EXPO and the table PERSONA, both having their corresponding
> ID fields.
>
>
>
> descriptorForTsExpo: aDescriptor
>
>             | table linkTable |
>
>             table := self tableNamed: 'EXPO'.
>
>             aDescriptor table: table.
>
>             self addNamedModelMappingsTo: aDescriptor table: table.
>
>             (aDescriptor newMapping: DirectMapping) from: #startDate to:
> (table fieldNamed: 'startDate').
>
>             (aDescriptor newMapping: DirectMapping) from: #endDate to:
> (table fieldNamed: 'endDate').
>
>             linkTable := self tableNamed: 'EXPO_ON_PERSONA'.
>
>             (aDescriptor newMapping: ManyToManyMapping)
>
>                         attributeName: #personas;
>
>                         referenceClass: TsPersona;
>
>                         join: (Join
>
>                                                from: (table fieldNamed:
> 'id')
>
>                                                to: (linkTable fieldNamed:
> 'persona_id')) "With or without the join is the same".
>
>
>
> classModelForTsExpo: aClassModel
>
>             self addNamedModelAttributesTo: aClassModel.
>
>             aClassModel newAttributeNamed: #startDate.
>
>             aClassModel newAttributeNamed: #endDate.
>
>             aClassModel newAttributeNamed: #personas collectionOf:
> TsPersona.
>
>
>
>
>
>
>
> tableForEXPO_ON_PERSONA: aTable
>
>             | expoKey personaKey |
>
>             expoKey := aTable createFieldNamed: 'expo_id' type: (platform
> int4).
>
>             aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO')
> fieldNamed: 'id').
>
>
>
>             personaKey := aTable createFieldNamed: 'persona_id' type:
> (platform int4).
>
>             aTable addForeignKeyFrom: personaKey  to: ((self tableNamed:
> 'PERSONA') fieldNamed: 'id').
>
>
>
>             expoKey bePrimaryKey.
>
>             personaKey bePrimaryKey.
>
>
>
> Do you see anything particularly wrong here?
>
> I played game of differences against the ManyToMany tests, but couldn't
> discern what is missing in my code.
>
>
>
> I found an example using
>
> #polymorphicJoinToItemFromField: aField
>
>             "Return a polymorphic join to the GlorpInventoryItem subclasses
> from the given field."
>
>
>
> My TsPersona class is an abstract class, but I also tried with non-abstract
> (it is, no type resolvers) classes, and I got the same error.
>
>
>
>
>
>
>
>
>
> Regards!
>
> --
> 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 http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "glorp-group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/glorp-group/fxkjLVld2AE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: ManyToManyMappings with link table

Wallen, David
Hi Esteban,

The only way I know of is to download the PUL version (Personal Use License is free, full version basically), for example from:
http://www.cincomsmalltalk.com/main/developer-community/trying-cincom-smalltalk/try-cincom-smalltalk/
Once you install it, GlorpGuide.pdf is in the 'doc' directory, and the example is in the Glorp directory.
- Dave

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban A. Maringolo
Sent: Monday, April 28, 2014 4:02 PM
To: [hidden email]
Subject: Re: ManyToManyMappings with link table

David,

I'm using Pharo port of GLORP, do you have a link to the
GlorpGuide.pdf, I couldn't find it online.

Best regards,

Esteban A. Maringolo


2014-04-28 19:21 GMT-03:00 Wallen, David <[hidden email]>:

> You could also have a look at the GlorpGuide pdf. There’s a companion
> example that may be somewhat similar to your example, called
> MyAppDescriptorSystem (GlorpGuide.pcl)
>
> - Dave
>
>
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Verleysen, Dirk
> Sent: Monday, April 28, 2014 2:13 PM
> To: [hidden email]
> Subject: RE: ManyToManyMappings with link table
>
>
>
> Are you sure you’re updating the same objects that you read from the
> database ?
>
>
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Esteban A. Maringolo
> Sent: maandag 28 april 2014 23:05
> To: [hidden email]
> Subject: Re: ManyToManyMappings with link table
>
>
>
> I looked at the test examples and found nothing different. I even tried
> specifying the Join explicitely.
>
> "GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique
> constraint.."
>
>
>
> I have the table EXPO and the table PERSONA, both having their corresponding
> ID fields.
>
>
>
> descriptorForTsExpo: aDescriptor
>
>             | table linkTable |
>
>             table := self tableNamed: 'EXPO'.
>
>             aDescriptor table: table.
>
>             self addNamedModelMappingsTo: aDescriptor table: table.
>
>             (aDescriptor newMapping: DirectMapping) from: #startDate to:
> (table fieldNamed: 'startDate').
>
>             (aDescriptor newMapping: DirectMapping) from: #endDate to:
> (table fieldNamed: 'endDate').
>
>             linkTable := self tableNamed: 'EXPO_ON_PERSONA'.
>
>             (aDescriptor newMapping: ManyToManyMapping)
>
>                         attributeName: #personas;
>
>                         referenceClass: TsPersona;
>
>                         join: (Join
>
>                                                from: (table fieldNamed:
> 'id')
>
>                                                to: (linkTable fieldNamed:
> 'persona_id')) "With or without the join is the same".
>
>
>
> classModelForTsExpo: aClassModel
>
>             self addNamedModelAttributesTo: aClassModel.
>
>             aClassModel newAttributeNamed: #startDate.
>
>             aClassModel newAttributeNamed: #endDate.
>
>             aClassModel newAttributeNamed: #personas collectionOf:
> TsPersona.
>
>
>
>
>
>
>
> tableForEXPO_ON_PERSONA: aTable
>
>             | expoKey personaKey |
>
>             expoKey := aTable createFieldNamed: 'expo_id' type: (platform
> int4).
>
>             aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO')
> fieldNamed: 'id').
>
>
>
>             personaKey := aTable createFieldNamed: 'persona_id' type:
> (platform int4).
>
>             aTable addForeignKeyFrom: personaKey  to: ((self tableNamed:
> 'PERSONA') fieldNamed: 'id').
>
>
>
>             expoKey bePrimaryKey.
>
>             personaKey bePrimaryKey.
>
>
>
> Do you see anything particularly wrong here?
>
> I played game of differences against the ManyToMany tests, but couldn't
> discern what is missing in my code.
>
>
>
> I found an example using
>
> #polymorphicJoinToItemFromField: aField
>
>             "Return a polymorphic join to the GlorpInventoryItem subclasses
> from the given field."
>
>
>
> My TsPersona class is an abstract class, but I also tried with non-abstract
> (it is, no type resolvers) classes, and I got the same error.
>
>
>
>
>
>
>
>
>
> Regards!
>
> --
> 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 http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "glorp-group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/glorp-group/fxkjLVld2AE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.

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

--
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 http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: ManyToManyMappings with link table

Alan Knight
The cache is at the GlorpSession level, but the changes are tracked inside the unit of work. Also note that you must register an object BEFORE you make changes to it. In VW it can actually hook into immutability to do that automatically when you modify the object, but I don't know that anyone has implemented that for Pharo. I'm not even sure Pharo has that write barrier.

So when you do it as
   session transact: [   "starts a unit of work"
        session register: expo.   "Makes a copy of the state of expo and the things that are transitively reachable from it"
        expo personas add: Persona new. "Modify the object"
   ]    "At the end, generates rows for all the modified objects and compares them. Writes new rows, or the modified portions of modified rows"

It should be fine in a web app. The best thing to do is that every time you have an interaction with the user it's saved to some sort of permanent storage. That way a disconnect or a timeout doesn't lose their intermediate state. However, that may make the object model more complicated. But if you're saving their state in a session, then that means you need a long-lived session specific to that user, and you can just as easily have a long-lived unit of work for that user. 


On Mon Apr 28 2014 at 4:12:26 PM, Wallen, David <[hidden email]> wrote:
Hi Esteban,

The only way I know of is to download the PUL version (Personal Use License is free, full version basically), for example from:
http://www.cincomsmalltalk.com/main/developer-community/trying-cincom-smalltalk/try-cincom-smalltalk/
Once you install it, GlorpGuide.pdf is in the 'doc' directory, and the example is in the Glorp directory.
- Dave

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban A. Maringolo
Sent: Monday, April 28, 2014 4:02 PM
To: [hidden email]
Subject: Re: ManyToManyMappings with link table

David,

I'm using Pharo port of GLORP, do you have a link to the
GlorpGuide.pdf, I couldn't find it online.

Best regards,

Esteban A. Maringolo


2014-04-28 19:21 GMT-03:00 Wallen, David <[hidden email]>:
> You could also have a look at the GlorpGuide pdf. There’s a companion
> example that may be somewhat similar to your example, called
> MyAppDescriptorSystem (GlorpGuide.pcl)
>
> - Dave
>
>
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Verleysen, Dirk
> Sent: Monday, April 28, 2014 2:13 PM
> To: [hidden email]
> Subject: RE: ManyToManyMappings with link table
>
>
>
> Are you sure you’re updating the same objects that you read from the
> database ?
>
>
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Esteban A. Maringolo
> Sent: maandag 28 april 2014 23:05
> To: [hidden email]
> Subject: Re: ManyToManyMappings with link table
>
>
>
> I looked at the test examples and found nothing different. I even tried
> specifying the Join explicitely.
>
> "GlorpDatabaseWriteError: ERROR:  duplicate key value violates unique
> constraint.."
>
>
>
> I have the table EXPO and the table PERSONA, both having their corresponding
> ID fields.
>
>
>
> descriptorForTsExpo: aDescriptor
>
>             | table linkTable |
>
>             table := self tableNamed: 'EXPO'.
>
>             aDescriptor table: table.
>
>             self addNamedModelMappingsTo: aDescriptor table: table.
>
>             (aDescriptor newMapping: DirectMapping) from: #startDate to:
> (table fieldNamed: 'startDate').
>
>             (aDescriptor newMapping: DirectMapping) from: #endDate to:
> (table fieldNamed: 'endDate').
>
>             linkTable := self tableNamed: 'EXPO_ON_PERSONA'.
>
>             (aDescriptor newMapping: ManyToManyMapping)
>
>                         attributeName: #personas;
>
>                         referenceClass: TsPersona;
>
>                         join: (Join
>
>                                                from: (table fieldNamed:
> 'id')
>
>                                                to: (linkTable fieldNamed:
> 'persona_id')) "With or without the join is the same".
>
>
>
> classModelForTsExpo: aClassModel
>
>             self addNamedModelAttributesTo: aClassModel.
>
>             aClassModel newAttributeNamed: #startDate.
>
>             aClassModel newAttributeNamed: #endDate.
>
>             aClassModel newAttributeNamed: #personas collectionOf:
> TsPersona.
>
>
>
>
>
>
>
> tableForEXPO_ON_PERSONA: aTable
>
>             | expoKey personaKey |
>
>             expoKey := aTable createFieldNamed: 'expo_id' type: (platform
> int4).
>
>             aTable addForeignKeyFrom: expoKey to: ((self tableNamed: 'EXPO')
> fieldNamed: 'id').
>
>
>
>             personaKey := aTable createFieldNamed: 'persona_id' type:
> (platform int4).
>
>             aTable addForeignKeyFrom: personaKey  to: ((self tableNamed:
> 'PERSONA') fieldNamed: 'id').
>
>
>
>             expoKey bePrimaryKey.
>
>             personaKey bePrimaryKey.
>
>
>
> Do you see anything particularly wrong here?
>
> I played game of differences against the ManyToMany tests, but couldn't
> discern what is missing in my code.
>
>
>
> I found an example using
>
> #polymorphicJoinToItemFromField: aField
>
>             "Return a polymorphic join to the GlorpInventoryItem subclasses
> from the given field."
>
>
>
> My TsPersona class is an abstract class, but I also tried with non-abstract
> (it is, no type resolvers) classes, and I got the same error.
>
>
>
>
>
>
>
>
>
> Regards!
>
> --
> 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 http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "glorp-group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/glorp-group/fxkjLVld2AE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/glorp-group.
> For more options, visit https://groups.google.com/d/optout.

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

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

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