Permalink
Browse files

emit 'new' if model not loaded

  • Loading branch information...
1 parent 63d5945 commit 4652f33ba1695014576410bae6eaf0b3153e4f13 Mark Evans committed Mar 30, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/model.coffee
View
@@ -4,6 +4,10 @@ class egg.Model extends egg.Base
@_attrs = opts.attrs || {}
@constructor.instances().add(@)
super
+ if opts.loaded
+ @emit 'load', instance: @
+ else
+ @emit 'new', instance: @
destroy: (opts)->
@constructor.instances().remove(@)
@@ -24,8 +28,8 @@ class egg.Model extends egg.Base
@emit('load:many', from: storage, instances: instances, opts: opts)
@load: (opts={})->
- model = @create(opts)
- @emit('load', instance: model)
+ opts.loaded = true
+ @create(opts)
@where: (attrs)->
index = egg.Index.for(@instances(), Object.keys(attrs))

0 comments on commit 4652f33

Please sign in to comment.