[Nitro] Discussion about setting relationships with unsaved objects

George Moschovitis george.moschovitis at gmail.com
Sat Apr 1 04:43:53 EST 2006


Open the ticket please.

-g.

On 3/31/06, Bryan Soto <bryan.a.soto at gmail.com> wrote:
> Did this one ever get resolved? If not, we should open a ticket.
>
> Thanks.
>
> Bryan
>
> On 2/22/06, Rob Pitt <rob at motionpath.com> wrote:
> > That's a better idea - OK I'll just patch my project to throw Exceptions
> > until this is done.
> >
> > On Wed, 2006-02-22 at 14:14 +0200, George Moschovitis wrote:
> > > Please don't make this change yet.I would like to add a 'build' mode
> > > in collections.
> > > Ie, You create an object, assign the relations and save in one go.
> > > Will add this during next week, so be patient.
> > >
> > > -g.
> > >
> > >
> > > On 2/22/06, Rob Pitt <rob at motionpath.com> wrote:
> > > > Currently in Og if you try and assign has many or joins many
> > > > relationships to an unsaved object, the object is silently saved in the
> > > > background (this is needed to make the relationship work), but if you do
> > > > the same with refers_to/belongs_to/has_one, this does not happen,
> > > > instead Og proceeds as if everything is fine essentially ignoring your
> > > > request (and losing the relationship).
> > > >
> > > > I think all of these behaviours are wrong because you may not expect
> > > > your object to have been saved in the has_many/joins_many case and you
> > > > will not know why your code mysteriously breaks in the belongs_to case
> > > > (this actually bit me while writing a unit test the other day and it
> > > > took me a good five minutes to work out what was wrong).
> > > >
> > > > I believe that all of these cases should throw and exception as you
> > > > should not be trying to assign relationships to unsaved objects, but
> > > > before I make this happen I want to confirm with the list you agree this
> > > > is the appropriate course of action. This way informs you that your code
> > > > is broken and if you did want automatic saving all you'd need to do is:
> > > >
> > > > begin
> > > >  obj.relation = remote
> > > > rescue UnsavedException
> > > >  obj.save!
> > > >  remote.save!
> > > >  retry
> > > > end
> > > >
> > > > Of course, this is pretty silly since you should be doing:
> > > >
> > > > remote.save!
> > > > obj.relation = remote
> > > > obj.save!
> > > >
> > > > In your code anyway.
> > > >
> > > > At the very least, the refers_to/has_one/belongs_to relationships should
> > > > have the same behaviour as the other relationships, be that auto-saving
> > > > as they currently do, or as I believe, throwing exceptions.
> > > >
> > > > Comments?
> > > >
> > > > _______________________________________________
> > > > Nitro-general mailing list
> > > > Nitro-general at rubyforge.org
> > > > http://rubyforge.org/mailman/listinfo/nitro-general
> > > >
> > >
> > >
> > > --
> > > http://www.gmosx.com
> > > http://www.navel.gr
> > > http://www.nitrohq.com
> > >
> > > _______________________________________________
> > > Nitro-general mailing list
> > > Nitro-general at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/nitro-general
> >
> > _______________________________________________
> > Nitro-general mailing list
> > Nitro-general at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/nitro-general
> >
>
>
> --
> "Never tell people how to do things. Tell them what to do and they
> will surprise you with their ingenuity." —General George S. Patton
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>


--
http://www.gmosx.com
http://www.navel.gr
http://www.nitrohq.com




More information about the Nitro-general mailing list