Search code examples
persistencesmalltalkpharo

How to persist graphs presenting circular references in Voyage?


I'm having an issue I don't recall having had about half a year ago when trying out Voyage.

In my schema, a User has an instVar referencing all the Centers he belongs to, and a Center has an instVar referencing all of its Users, so when the Voyage serializer tries to serialize a user (or a center), it goes into an infinite loop trying to find the end of the reference chain and the image clogs.

I remember saving the exact same schema a while ago without a problem, is there something new I should know about?

BTW, I'm using the #bleedingEdge version, with Magritte3 and all.

Thanks! :)


Solution

  • I tried to reproduce your problem and it works fine in my example. What I did is this:

    You have a Star, who has Planets, who at it's time points to the owner Star.

    Star new 
        name: 'Sun';
        position: 10@12;
        addPlanet: (Planet new 
            name: 'Earth';
            orbit: 3;
            yourself);
        save
    

    Both possible combinations works for me:

    Star class>>#isVoyageRoot
        ^ true
    Planet class>>#isVoyageRoot
        ^ true
    

    and:

    Star class>>#isVoyageRoot
        ^ true
    Planet class>>#isVoyageRoot
        ^ false
    

    So... I don't know where is your error :(