How to model with ember-data


I am trying to model the following in ember-data and could do with some advice on how to proceed.

Conceptually, I have a listing which is created by a user and has various other fields e.g. dateCreated. Each listing has a specific product and each product will have a specific (and quite different) set of fields.

I am more used to working with languages which have algebraic data types and would typically model product as a sum type / tagged union e.g. (in Haskell)

data Product = ProductA { foo :: String, bar :: Int}
              | ProductB { baz :: Int}
              | ProductC { qux :: String } 

The listing type would then have a product field with type Product.

I understand that the relationship between listing and product can be modeled with belongsTo but do not know how to represent the fact the a product is always one of 3 distinct types of product.

If I treat a product as an untyped object don’t I lose the benefit of ember-data managing (de)serialization for me?

Can anyone advise on how to handle this in ember-data?

(Feel free to ignore the Haskell-y stuff if this is confusing the issue!)

Many thanks,


In case it saves time for someone else, what I wanted turned out to be polymorphic relationships. There is a very useful discussion and example of their use here.