to_amf nested include question

14 views
Skip to first unread message

Larry Erickson

unread,
Jan 18, 2011, 7:56:00 PM1/18/11
to restfulx-framework
Hello all.
I have been trying to upgrade my app from using fxml to amf. I went
to all my controllers and added corresponding format.amf
{ render :amf => model.to_amf()}. I did not change any of my
options from fxml and amf.

In theory I think I should be able to switch back and forth in Flex
from fxml and amf, just by what I set my
ApplicationController.initialize to. However, I am getting different
results.

It seems that when I try to do nested includeded with amf, I do not
get all the data I need.
My models are Rail, RailVisit, and Sling. My relationships are as
follows
Rail has_many RailVisits
RailVisit belongs_to Sling and Rail
Sling has_many RailVisits

I try to get all of the rail_visits and slings from the rail model,
and so my controllers look like(they are the same)
format.fxml { render :fxml => @rails.to_fxml(:except =>
[:updated_at, :incoming_priority], :methods =>
[:attachment_url], :include=>{ :rail_visits=>{:include=>:sling}, :washer_communication
=> {}}, :order => :number)}
format.amf { render :amf => @rails.to_amf(:except =>
[:updated_at, :incoming_priority], :methods =>
[:attachment_url], :include=>{ :rail_visits=>{:include=>:sling}, :washer_communication
=> {}}, :order => :number)}

When I use amf I do not get all the sling properties in flex which
causes errors. Wondering if this makes sense, if I am missing
something, or if I am not understanding something.

Thanks,

Larry

Dariel Subiros

unread,
Jan 19, 2011, 8:48:32 AM1/19/11
to restfulx-...@googlegroups.com
Hi Larry:

To use amf do this:

In your application's init method:

ApplicationController.initialize([AMFServiceProvider], AMFServiceProvider.ID);
 
Then add in config/initializers/restfulx.rb

# Set up the default namespace for serializing Rails models to AMF
RestfulX::AMF::ClassMapper.default_as_prefix = "yourflexpackage.models"

Where says yourflexpackage you should put your main flex package's name, this should be tha same as your application's name but everything in downcase(eg. from application name: ComputersControl  then flexpackage: computerscontrol)

Hope this helps.
Dariel.


--
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.


Larry Erickson

unread,
Jan 19, 2011, 9:38:52 AM1/19/11
to restfulx-framework
Thanks for the response Dariel. I already had that line added to the
restfulx initializer. I should have pointed out that amf is working
for the most part. On many of my models it is working 100%
correctly. It only appears to not be behaving the same way as fxml on
some models where I get all associations using nested includes.

Thanks,

Larry

On Jan 19, 7:48 am, Dariel Subiros <dsubi...@gmail.com> wrote:
> Hi Larry:
>
> To use amf do this:
>
> In your application's init method:
>
> ApplicationController.initialize([AMFServiceProvider],
> AMFServiceProvider.ID);
>
> Then add in config/initializers/restfulx.rb
>
> # Set up the default namespace for serializing Rails models to AMF
> RestfulX::AMF::ClassMapper.default_as_prefix = "yourflexpackage.models"
>
> Where says yourflexpackage you should put your main flex package's name,
> this should be tha same as your application's name but everything in
> downcase(eg. from application name: ComputersControl  then flexpackage:
> computerscontrol)
>
> Hope this helps.
> Dariel.
>
> > restfulx-framew...@googlegroups.com<restfulx-framework%2Bunsubs cr...@googlegroups.com>
> > .

Dima Berastau

unread,
Jan 19, 2011, 4:12:29 PM1/19/11
to restfulx-...@googlegroups.com
Could you make a bug report out of this with ideally a small rails2 app that can be used for testing?

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.

Larry Erickson

unread,
Jan 19, 2011, 4:53:02 PM1/19/11
to restfulx-framework
Sure Dima. I noticed that this issue appears to be the same as an
already closed issue.
https://github.com/dima/restfulx/issues/closed#issue/6

The following works:
@projects.to_amf(:include => [:sprints])
However, the following is broken:
@project.to_amf(:include => {:sprints => {:include => [:tasks]}}

When I try out the nested association in a rails console, it only
shows amf response data for the project and sprint levels, not the
tasks.
Don't really know how to make complete sense out of console amf
output, but just wondering if that means something.

Dariel Subiros

unread,
Jan 19, 2011, 5:18:56 PM1/19/11
to restfulx-...@googlegroups.com
Hi Larry:

Try using [:tasks] between {}.

Hope this helps.
Dariel

Dariel Subiros

unread,
Jan 19, 2011, 5:19:44 PM1/19/11
to restfulx-...@googlegroups.com
Sorry for this, I mean, {} instead of [].

Dariel

Dima Berastau

unread,
Jan 19, 2011, 7:37:22 PM1/19/11
to restfulx-...@googlegroups.com
Hi Larry,

You can refer to https://github.com/dima/pomodo_on_rails for an example of how to do serialization using nested includes. In particular refer to projects_controller.rb

Hope this helps,
Dima

> To unsubscribe from this group, send email to restfulx-framew...@googlegroups.com.

Larry Erickson

unread,
Jan 20, 2011, 8:19:59 AM1/20/11
to restfulx-framework
Thanks Dima. Looking at the projects_controller, I was able to see
how to properly do a nested include.

I don't really understand the difference but I was doing

@projects.to_amf(:include=>{:sprints=>{:include=>:tasks}})

which did not work, and needed to be doing

@projects.to_amf(:include => {:sprints => {:include => {:tasks =>
{}}}})


The first way did work with fxml but not amf, the second way works
with both.

Thanks,

Larry

On Jan 19, 6:37 pm, Dima Berastau <dima.beras...@gmail.com> wrote:
> Hi Larry,
>
> You can refer tohttps://github.com/dima/pomodo_on_railsfor an example of how to do serialization using nested includes. In particular refer to projects_controller.rb

Larry Erickson

unread,
Feb 7, 2011, 1:35:18 PM2/7/11
to restfulx-framework
Just throwing this out there to see if it makes sense. I am seeing
different behavior when I switch my application back and forth between
using fxml and amf.

When the app starts I do a
Rx.models.index(Project, null, null, null, null, true, true);
A project has_many sprints, and so all sprints associated with a
project are fetched.
My controllers are the exact same for amf and fxml, using proper
includes.
The sql generated appears to be the exact same for amf and fxml.

The difference, which was causing me problems, was that with fxml
Rx.models.cached(Sprint) returns a collection of sprints while with
amf Rx.models.cached(Sprint) returns null.

Is there a reason for that? Could something else be different that I
am not factoring in?

Thanks,

Larry



On Jan 20, 7:19 am, Larry Erickson <larry.erick...@gmail.com> wrote:
> Thanks Dima.    Looking at the projects_controller, I was able to see
> how to properly do a nested include.
>
> I don't really understand the difference but I was doing
>
>     @projects.to_amf(:include=>{:sprints=>{:include=>:tasks}})
>
> which did not work, and needed to be doing
>
>     @projects.to_amf(:include => {:sprints =>  {:include => {:tasks =>
> {}}}})
>
> The first way did work with fxml but not amf, the second way works
> with both.
>
> Thanks,
>
> Larry
>
> On Jan 19, 6:37 pm, Dima Berastau <dima.beras...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi Larry,
>
> > You can refer tohttps://github.com/dima/pomodo_on_railsforan example of how to do serialization using nested includes. In particular refer to projects_controller.rb
Reply all
Reply to author
Forward
0 new messages