Mongo lost references - bug?

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

Mongo lost references - bug?

Sabine Manaa
Hi Esteban,

I found a problem in mongo/voyage and I have reduced and extracted it for repro.
I ask for your opinion if this is a bug.

If you file in the code below, the method >>testDemo creates a simple model:
Paper has 1:1 reference to Planet.
Paper has 1:1 reference to Star.
Star has 1:N reference to Planet.
Star has 1:1 reference to Paper.
Planet has 1:1 reference to Paper.

If you run >>testDemo, you see that the model which was created is ok with all its references.
(self assert: thePaper planet = thePaper star planets first.) ==> ok

If you reset the repository and load Paper from database with
Paper select all
and make the same check, the references are lost.

VORepository current reset.
theReloadedPaper := Paper selectAll first.
self assert: theReloadedPaper planet = theReloadedPaper star planets first ==>not ok

But if you remove the comment within >>mongoPlanets
which leads to sending a message to the newly loaded object, then it works.

write: [ :star :planets | star planets: (planets "select: [:each | each someMethod]")  ]);

Do I have to send a message to each of the instances after loading? I think no.

If I did not understand correctly how to use voyage, please tell me.

Regards
Sabine




Object subclass: #Planet
        instanceVariableNames: 'planetname star paper'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'RKA24-Demo'!

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper
        ^ paper! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper: anObject
        paper := anObject! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:17'!
planetname
        ^ planetname! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:17'!
planetname: anObject
        planetname := anObject! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:53'!
star
        ^ star! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:53'!
star: anObject
        star := anObject! !


!Planet methodsFor: 'testing' stamp: 'sabineknoefel 12/2/2013 12:25'!
someMethod
        ^true! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Planet class
        instanceVariableNames: ''!

!Planet class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 7/18/2013 16:16'!
isVoyageRoot
        ^true! !

!Planet class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 12/2/2013 12:23'!
mongoStar
        <mongoDescription>
        ^ VOMongoToOneDescription new
                attributeName: 'star';
                kind: Star;
                accessor: (MAPluggableAccessor read: [ :planet | planet star ] write: [ :planet :star | planet star: star ]);
                yourself! !

!Planet class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 12/2/2013 12:30'!
testDemo
        "self testDemo"

        | thePlanet theStar thePaper theReloadedPaper |
        "create simple model"
        thePaper := Paper new theme: 'a paper about 42'.
        thePlanet := Planet new planetname: 'Orion'; paper: thePaper.
        theStar := Star new starname: 'Betelgeuse'; paper: thePaper.
        theStar addPlanet: thePlanet.
        thePaper star: theStar.
        thePaper planet: thePlanet.
        thePaper save.
       
        "check references - ok"
        self assert: thePaper planet = thePaper star planets first.
       
        VORepository current reset.
        theReloadedPaper := Paper selectAll first.
        "references are lost now"
        self assert: theReloadedPaper planet = theReloadedPaper star planets first! !


Object subclass: #Star
        instanceVariableNames: 'starname planets paper'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'RKA24-Demo'!

!Star methodsFor: 'api' stamp: 'sabineknoefel 7/18/2013 16:21'!
addPlanet: aPlanet
        self planets add: aPlanet.
        aPlanet star: self! !


!Star methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper
        ^ paper! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper: anObject
        paper := anObject! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:20'!
planets
        planets ifNil: [ self planets: OrderedCollection new ].
        ^ planets! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:20'!
planets: anObject
        planets := anObject! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:18'!
starname
        ^ starname! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:18'!
starname: anObject
        starname := anObject! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Star class
        instanceVariableNames: ''!

!Star class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 7/18/2013 16:16'!
isVoyageRoot
        ^true! !

!Star class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 12/2/2013 12:31'!
mongoPlanets
        "remove comment below then references are not lost anymore"

        <mongoDescription>
        ^ VOMongoToManyDescription new
                attributeName: 'planets';
                kind: Planet;
                accessor:
                                (MAPluggableAccessor
                                                read: [ :star | star planets ]
                                                write: [ :star :planets | star planets: (planets "select: [:each | each someMethod]")  ]);
                yourself ! !


Object subclass: #Paper
        instanceVariableNames: 'star planet theme'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'RKA24-Demo'!

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
planet
       
        ^ planet! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
planet: anObject
       
        planet := anObject! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
star
       
        ^ star! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
star: anObject
       
        star := anObject! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
theme
       
        ^ theme! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
theme: anObject
       
        theme := anObject! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Paper class
        instanceVariableNames: ''!

!Paper class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 12/2/2013 11:48'!
isVoyageRoot
        ^true! !

!Paper class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 12/2/2013 12:23'!
mongoPlanet
        <mongoDescription>
        ^ VOMongoToOneDescription new
                attributeName: 'planet';
                accessor: (MAPluggableAccessor
                        read: [ :paper | paper planet ]
                        write: [ :paper :planet | paper planet: planet ]);
                yourself! !

!Paper class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel 12/2/2013 12:23'!
mongoStar
        <mongoDescription>
        ^ VOMongoToOneDescription new
                attributeName: 'star';
                accessor: (MAPluggableAccessor
                        read: [ :paper | paper star ]
                        write: [ :paper :star | paper star: star ]);
                yourself! !
Reply | Threaded
Open this post in threaded view
|

Re: Mongo lost references - bug?

EstebanLM
Hi Sabine, 
I'll check, but you shouldn't have that problem, so is probably a bug :)

Esteban


On Mon, Dec 2, 2013 at 12:51 PM, Sabine Knöfel <[hidden email]> wrote:
Hi Esteban,

I found a problem in mongo/voyage and I have reduced and extracted it for
repro.
I ask for your opinion if this is a bug.

If you file in the code below, the method >>testDemo creates a simple model:
Paper has 1:1 reference to Planet.
Paper has 1:1 reference to Star.
Star has 1:N reference to Planet.
Star has 1:1 reference to Paper.
Planet has 1:1 reference to Paper.

If you run >>testDemo, you see that the model which was created is ok with
all its references.
(self assert: thePaper planet = thePaper star planets first.) ==> ok

If you reset the repository and load Paper from database with
Paper select all
and make the same check, the references are lost.

VORepository current reset.
theReloadedPaper := Paper selectAll first.
self assert: theReloadedPaper planet = theReloadedPaper star planets first
==>not ok

But if you remove the comment within >>mongoPlanets
which leads to sending a message to the newly loaded object, then it works.

write: [ :star :planets | star planets: (planets "select: [:each | each
someMethod]")  ]);

Do I have to send a message to each of the instances after loading? I think
no.

If I did not understand correctly how to use voyage, please tell me.

Regards
Sabine




Object subclass: #Planet
        instanceVariableNames: 'planetname star paper'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'RKA24-Demo'!

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper
        ^ paper! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper: anObject
        paper := anObject! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:17'!
planetname
        ^ planetname! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:17'!
planetname: anObject
        planetname := anObject! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:53'!
star
        ^ star! !

!Planet methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:53'!
star: anObject
        star := anObject! !


!Planet methodsFor: 'testing' stamp: 'sabineknoefel 12/2/2013 12:25'!
someMethod
        ^true! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Planet class
        instanceVariableNames: ''!

!Planet class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
7/18/2013 16:16'!
isVoyageRoot
        ^true! !

!Planet class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
12/2/2013 12:23'!
mongoStar
        <mongoDescription>
        ^ VOMongoToOneDescription new
                attributeName: 'star';
                kind: Star;
                accessor: (MAPluggableAccessor read: [ :planet | planet star ] write: [
:planet :star | planet star: star ]);
                yourself! !

!Planet class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
12/2/2013 12:30'!
testDemo
        "self testDemo"

        | thePlanet theStar thePaper theReloadedPaper |
        "create simple model"
        thePaper := Paper new theme: 'a paper about 42'.
        thePlanet := Planet new planetname: 'Orion'; paper: thePaper.
        theStar := Star new starname: 'Betelgeuse'; paper: thePaper.
        theStar addPlanet: thePlanet.
        thePaper star: theStar.
        thePaper planet: thePlanet.
        thePaper save.

        "check references - ok"
        self assert: thePaper planet = thePaper star planets first.

        VORepository current reset.
        theReloadedPaper := Paper selectAll first.
        "references are lost now"
        self assert: theReloadedPaper planet = theReloadedPaper star planets first!
!


Object subclass: #Star
        instanceVariableNames: 'starname planets paper'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'RKA24-Demo'!

!Star methodsFor: 'api' stamp: 'sabineknoefel 7/18/2013 16:21'!
addPlanet: aPlanet
        self planets add: aPlanet.
        aPlanet star: self! !


!Star methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper
        ^ paper! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 12:05'!
paper: anObject
        paper := anObject! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:20'!
planets
        planets ifNil: [ self planets: OrderedCollection new ].
        ^ planets! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:20'!
planets: anObject
        planets := anObject! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:18'!
starname
        ^ starname! !

!Star methodsFor: 'accessing' stamp: 'sabineknoefel 7/18/2013 16:18'!
starname: anObject
        starname := anObject! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Star class
        instanceVariableNames: ''!

!Star class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
7/18/2013 16:16'!
isVoyageRoot
        ^true! !

!Star class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
12/2/2013 12:31'!
mongoPlanets
        "remove comment below then references are not lost anymore"

        <mongoDescription>
        ^ VOMongoToManyDescription new
                attributeName: 'planets';
                kind: Planet;
                accessor:
                                (MAPluggableAccessor
                                                read: [ :star | star planets ]
                                                write: [ :star :planets | star planets: (planets "select: [:each |
each someMethod]")  ]);
                yourself ! !


Object subclass: #Paper
        instanceVariableNames: 'star planet theme'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'RKA24-Demo'!

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
planet

        ^ planet! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
planet: anObject

        planet := anObject! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
star

        ^ star! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
star: anObject

        star := anObject! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
theme

        ^ theme! !

!Paper methodsFor: 'accessing' stamp: 'sabineknoefel 12/2/2013 11:54'!
theme: anObject

        theme := anObject! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Paper class
        instanceVariableNames: ''!

!Paper class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
12/2/2013 11:48'!
isVoyageRoot
        ^true! !

!Paper class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
12/2/2013 12:23'!
mongoPlanet
        <mongoDescription>
        ^ VOMongoToOneDescription new
                attributeName: 'planet';
                accessor: (MAPluggableAccessor
                        read: [ :paper | paper planet ]
                        write: [ :paper :planet | paper planet: planet ]);
                yourself! !

!Paper class methodsFor: 'as yet unclassified' stamp: 'sabineknoefel
12/2/2013 12:23'!
mongoStar
        <mongoDescription>
        ^ VOMongoToOneDescription new
                attributeName: 'star';
                accessor: (MAPluggableAccessor
                        read: [ :paper | paper star ]
                        write: [ :paper :star | paper star: star ]);
                yourself! !




--
View this message in context: http://forum.world.st/Mongo-lost-references-bug-tp4726673.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Mongo lost references - bug?

Sabine Manaa
Hi Esteban,

I had a look again and I think it is a bug. Could you have a look please?

Regards
Sabine
Reply | Threaded
Open this post in threaded view
|

Re: Mongo lost references - bug?

EstebanLM
Hi Sabine,

I need a bit more references than that :)
Obviously for the way you refer to the problem, we have talked about it… but I do not remember it :(
Can you point me to the original thread?

cheers!
Esteban

> On 16 Aug 2015, at 17:28, Sabine Manaa <[hidden email]> wrote:
>
> Hi Esteban,
>
> I had a look again and I think it is a bug. Could you have a look please?
>
> Regards
> Sabine
>
>
>
> --
> View this message in context: http://forum.world.st/Mongo-lost-references-bug-tp4726673p4843290.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Mongo lost references - bug?

Sabine Manaa
Hi Esteban,

it was already in the mail, it is this thread:

I attach the file in.

Regards
Sabine

2015-08-17 10:42 GMT+02:00 EstebanLM [via Smalltalk] <[hidden email]>:
Hi Sabine,

I need a bit more references than that :)
Obviously for the way you refer to the problem, we have talked about it… but I do not remember it :(
Can you point me to the original thread?

cheers!
Esteban

> On 16 Aug 2015, at 17:28, Sabine Manaa <[hidden email]> wrote:
>
> Hi Esteban,
>
> I had a look again and I think it is a bug. Could you have a look please?
>
> Regards
> Sabine
>
>
>
> --
> View this message in context: http://forum.world.st/Mongo-lost-references-bug-tp4726673p4843290.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>





If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Mongo-lost-references-bug-tp4726673p4843400.html
To start a new topic under Pharo Smalltalk Users, email [hidden email]
To unsubscribe from Mongo lost references - bug?, click here.
NAML


test.st (8K) Download Attachment