diff --git a/tests/tests.coffee b/tests/tests.coffee index 211d9f7..968c2e5 100644 --- a/tests/tests.coffee +++ b/tests/tests.coffee @@ -15,7 +15,9 @@ Tinytest.add 'has an_embedded - team has an embedded headquarter', (test) -> test.equal xmen.headquarter.name, xmansion.name Tinytest.add 'has many_embedded - team has many embedded vehicles', (test) -> - test.equal xmen.vehicles, [blackbird, aston] + xmen_vehicle_names = (vehicle.name for vehicle in xmen.vehicles) + vehicle_names = (vehicle.name for vehicle in [blackbird, aston]) + test.equal xmen_vehicle_names, vehicle_names # all diff --git a/tinymodel.coffee b/tinymodel.coffee index daaeb53..970959f 100644 --- a/tinymodel.coffee +++ b/tinymodel.coffee @@ -6,12 +6,11 @@ class @TinyModel constructor: (params={}) -> for field,value of params - embedded = @constructor.an_embedded - if embedded? and embedded[field]? - klass = app[embedded[field]] + if @constructor.an_embedded? and @constructor.an_embedded[field]? + klass = app[@constructor.an_embedded[field]] @[field] = new klass(value) - else if many_embedded? and many_embedded[field]? - klass = app[many_embedded[field]] + else if @constructor.many_embedded? and @constructor.many_embedded[field]? + klass = app[@constructor.many_embedded[field]] @[field] = (new klass(params) for params in value) else @[field] = value