undefined method serializable_add_includes

55 views
Skip to first unread message

Lyle Underwood

unread,
Feb 8, 2011, 9:38:22 PM2/8/11
to rubyamf
Hey again,

I'm working with rails3-amf and MongoDB. I'm trying to do this:

format.amf { render :amf => @articles.collect.to_amf(:include => [:category]) }

And I get the following error:

undefined method `serializable_add_includes' for #<Article:0xb6759084>

I can call Article.serializable_hash(:include => :category) and that
works fine, but of course it does not have a to_amf method.

Any help appreciated,
Lyle

warhammerkid

unread,
Feb 9, 2011, 10:29:59 AM2/9/11
to rubyamf
Lyle,

Short story:
For now only ActiveRecord has support for :include in to_amf. You
could probably replicate the behavior you want by calling
@articles.collect.to_amf(:methods => [:category]) for now.

Long story:
ActiveModel is the base model class for all Rails 3-compatible ORMs.
Unfortunately it doesn't have any concept of relations - only
ActiveRecord has that. Because of the way to_amf and serializable_hash
work, I can't directly use serializable_hash for the relations
portion. The reason is that I need to intercept the objects in the
relation before they're turned into hashes so that if you have
"Category" mapped to "vo.Category" in Actionscript the mapping passes
through. Once it's a hash, I can't determine the original class name.
So when you use include, it assumes you're working with an
ActiveRecord object and calls serializable_add_includes.

If you'd like to add support for relations through MongoDB, take a
look at how ActiveRecord implements serializable_add_includes (https://
github.com/rails/rails/blob/master/activerecord/lib/active_record/
serialization.rb) and add a method that replicates that behavior to
the MongoDB base model class. I'm working together with several other
developers from the RubyAMF team to put together a better solution to
this, but for now this is the only way to do it.

Stephen

Lyle Underwood

unread,
Feb 9, 2011, 1:02:03 PM2/9/11
to rub...@googlegroups.com
You are a beautiful man.

I will check that out, but :methods is working beautifully for now.

Thanks.

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

Reply all
Reply to author
Forward
0 new messages