Active Record Methods - wouterj/snakeMvc GitHub Wiki
De active record methods die zijn overgenomen van Ruby On Rails:
Create
======
p = Post.new
p.title = 'Hello World'
p.author = 'Wouter J'
p.content = 'Lorem ipsum'
p.save
p = Post.new(:title => 'Hello World', :author => 'Wouter J', :content => 'Lorem Ipsum')
p.save
Post.create(:title => 'Hello World', :author => 'Wouter J', :content => 'Lorem Ipsum')
Read
====
Post.find(2) 1 item with id = 2
Post.find(3,5,6) array where id = 3,5,6
Post.first the first item
Post.last the last item
Post.all all items
Post.count count query
Post.order(:author) order by author
Post.limit(10) the first 10
Post.where(:author => 'Wouter J') where author = Wouter J
Post.where(:author => 'Wouter J').order(:create).limit(10) method chaining
Update
======
p = Post.find(3)
p.title = 'New title'
p.save
p = Post.find(3)
p.attributes = {
:title => 'New title',
:content => 'new content'
}
p.save
p = Post.find(3)
p.update_attributes(
:title => 'New title',
:content => 'new content'
)
Delete
======
p = Post.find(2)
p.destroy
Post.find(2).destroy
Post.destroy_all