AMF object inheritance?

4 views
Skip to first unread message

Trisweb

unread,
Mar 31, 2008, 4:52:08 PM3/31/08
to rubyamf
I'm having an issue with something a little complex, and I'm wondering
if it's supported either by RubyAMF, or even the AMF protocol at all
(if so then I will implement it). Here's the situation:

I have four classes with some inheritance going on in Rails (rough
pseudocode):

class Collection < ActiveRecord::Base

belongs_to :bitemporal, :class_name=>"CollectionBitemporal", :foreign_key=>"bitemporal_id"
end

class SpecialCollection < Collection
[bitemporal association is inherited, but the actual instance will
be a SpecialCollectionBitemporal]
end

In my case, what actually ends up in the SpecialCollection's
bitemporal association is a SpecialCollectionBitemporal, and an
instance of this class is sent correctly to Flex, which has the same
Object model for the VO's+Model objects as Rails does (same
inheritance and all).

But, that's where the problem starts. I get the error:
TypeError: Error #1034: Type Coercion failed: cannot convert
Object@87903f9 to model.CollectionBitemporal.
Because it's a SpecialCollectionBitemporal, not a
CollectionBitemporal, and the inheritance is not respected because the
objects are only known by their Class names coming from RubyAMF.

Does anyone know any way to get the inheritance working? Or is that
even supported under AMF?

Thanks in advance, I know this is a complicated model, but if at all
possible I want to do it the right (aka properly object oriented) way.
I'm open to other suggestions as well however.

Tony Hillerson

unread,
Mar 31, 2008, 9:32:15 PM3/31/08
to rubyamf
Are you saying that you have a SpecialCollectionBitemporal association
that Rails only knows as a CollectionBitemporal at the point it's sent
accross? In other words, do you have a superclass where the
Actionscript property is a type of a subclass?

The AMF spec doesn't have anything special about polymorphism built
in. The Flash player will convert a class C to a class C and get the
inherited properties from class B if C inherits B, but it won't know
that class incoming class B should really be a C. That's in line with
polymorphism rules, so it sounds like I must be misunderstanding
something.

In any case, if worst comes to worst, you still have the properties,
you're just not getting the automatic class conversion, so you can do
some conversion yourself if you need to.

I don't know how helpful that was...
Reply all
Reply to author
Forward
0 new messages