Loading...

ruboss-framework@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[ruboss-framework] Re: Has one association and transactions Dima Berastau Fri Jan 09 00:00:25 2009

Hi Renato,

It is indeed possible to save multiple related models at once. Here's  
what you have to do currently:

// this will produce a recursively marshalled representation of the  
model (with HasOne and HasMany relationships nested)
var marshalled:XML = Ruboss.serializers.xml.marshall(model, true);

Ruboss.http({onResult: onResultHandler, contentType: "application/ 
xml"}).invoke({URL: "/whatever/is/appropriate.fxml", data: marshalled,  
method = "POST", cacheBy: "create"});

See 
http://dima.github.com/ruboss_framework/org/ruboss/controllers/AuxHTTPController.html
 
  for details on Ruboss.http().invoke() options.

It's a bit more work than just <model>.create(). Recursive creates/ 
updates are likely to be more streamlined in the next release. For  
now, you have to marshall recursively and use Ruboss.http.

Of course, your Rails controller need to know what to do with nested  
data. Check out mass-assignment for one option: 
http://ryandaigle.com/articles/2008/7/19/what-s-new-in-edge-rails-nested-models

cheers,
Dima

On 8-Jan-09, at 3:14 PM, Renato Atilio wrote:

>
> Hello,
>
> I'm using a has_one association and I'd like to know if there is any
> way I can save the parts of the association in one transaction,
> sending just one xml instead of calling separately the save command in
> both instances.
>
> For example, I have a Person model which has_one Address. Let's
> suppose I'm creating a new Person and, at the same time, creating a
> new Address. What is the right approach so I can be sure that
> everything is saved and otherwise, If the save command fails in any
> part, the entire command is rolled back?
>
> The way I expected to use was something like setting the address
> attribute in the person instance, if the address.id is null, it will
> be saved in the same transaction with person. Of course, it didn't
> work. :)
>
> Any insight is appreciated.
>
> Thanks,
> Renato Atilio.
>
> >

Dima Berastau
CTO and Co-Founder, Ruboss Technology Corporation (www.ruboss.com)





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ruboss-framework" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ruboss-framework?hl=en
-~----------~----~----~----~------~----~------~--~---