#meteor-model
Move your <body> to <template name='body'>.
###Using meteorite
mrt add model
Copy whole lib/into your Meteor app.
Install the coffeescript package:
meteor add coffeescript
I've messed something up with packaging. Check usage demo here: meteor-model-demo
class User extends Model
@set_collection()
@belongs_to 'group'
isValid: ->
@name.length >= 3 and \
@age >= 18
class Group extends Model
@set_collection()
@has_many 'users'
User.new(name: 'Bob', age: 18).save()
set_collection generates reference to mongo collection and Template.modelName.collection.
#update ,
#destroy ,
.first ,
.where ,
.all ,
.count ,
.create ,
.destroy_all .
You can use create , .update , .destroy in html and it'll work out of the box. Demo in Haml (according to models from previous example):
%template{ name: :body }
{{> groups}}
%template{ name: :groups }
{{> new_group}}
/ collection is defined by Model
{{#each collection}}
{{> group}}
{{/each}}
%template{ name: :new_group }
/ create class will trigger action
%form.create{ model: :Group }
%input{ name: :name }
%button{ type: :submit } Add group
%template{ name: :group }
%h1 {{name}}
/ destroy class
.destroy Remove
{{> users}}
%template{ name: :users }
{{> new_user}}
{{#each collection}}
{{> user}}
{{/each}}
%template{ name: :new_user }
%form.create{ model: :User }
%input{ name: :name }
%input{ name: :age }
%button{ type: :submit } Add user
%template{ name: :user }
%h2 {{name}}
{{age}}
.destroy Remove.on_update ,
.on_destroy ,
.on_create .
.belongs_to ,
.has_many :
user = User.first()
user.group.new name: 'Group #2' # => Group
user.group() # => Group
group = Group.create name: 'G #3'
user.group.set group # => Group
group.users() # => Array[Group]
group.users(name: 'Bob') # => Array[Group]
#other
group.users.new name: 'Username' # => User
group.users.add User.first(name: 'Marek') # => User
User.create name: 'Bob', age: 18 # => User
User.create name: '' # => false Template.groups.collection = -> Group.all()
Templage.users.collection = -> @.users()
Template.users.events
'click .remove': -> @.destroy()Package under development. Proof of concept. Good for prototyping. There is no tests, but code is short and easy. You can fix bugs and add new features yourself. You're welcome to contribute or reporting.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request