Skip to content

Commit

Permalink
fixing many_embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
peterclark committed Jun 30, 2015
1 parent 26a98db commit 8a55152
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tests/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions tinymodel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a55152

Please sign in to comment.