Creating/Updating 3 levels deep models in one call

0 views
Skip to first unread message

Alex Tkachev

unread,
Dec 9, 2009, 3:17:41 AM12/9/09
to restfulx-framework
Hello,

I have the following models hierarchy:

class Zone < ActiveRecord::Base
has_one :zone_shape
end

class ZoneShape < ActiveRecord::Base
belongs_to :zone
has_many :zone_shape_points
end

class ZoneShapePoint < ActiveRecord::Base
belongs_to :zone_shape
end

In flex, I have a new zone created, associated with new ZoneShape
model which has several new ZoneShapePoints.
I need to save all this mess in one call (in ZonesController).
I've seen that there is support for recursive parameter but it works
only one level deep (i.e serializes only ZoneShape model but not
ZoneShapePoint models)... Also I don't have rails 2.3 so
accepts_nested_attributes isn't available....

Is there a way to do this? Please help me (a snippet of flex code &
controller code would be extremely appreciated cause I'm kinda newbie
with RestfulX stuff)...

Thanks,
Alex.

Dima Berastau

unread,
Dec 9, 2009, 5:07:14 PM12/9/09
to restfulx-...@googlegroups.com
Hi Alex,

XML/JSON Serializer in RestfulX will only serialize first level dependencies at the moment. While this is something that can be fixed to do multiple levels, you can try to work around this by splitting the request into 2 parts. e.g.

zone.create({onSuccess: onZoneCreate, recursive: true});

private function onZoneCreate(result:Zone):void {
//create zone shape points
}

You can create a ticket for this at http://github.com/dima/restfulx_framework/issues, so that we can see if this can be fixed for next release. If you feel like playing with RestfulX code, obviously feel free to fix this yourself :) Your contribution would be much appreciated.

Regards,
Dima
> --
>
> You received this message because you are subscribed to the Google Groups "restfulx-framework" group.
> To post to this group, send email to restfulx-...@googlegroups.com.
> To unsubscribe from this group, send email to restfulx-framew...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/restfulx-framework?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages