9. Lazy Loading
@posts = Post.all
#select id,title,created_at from posts;
@posts.each do |p|
puts p.body
#select body from posts where ....;
end
Only load what you need
( :fetch in 1.0? )
9
10. Lazy
p = Post.all
# no query happened!
p[0]
#select * from posts limit 1
Wait for the kicker methods:
each, map, count, etc.
10
12. Query Path
Post.all('comments.email.like' => 'contagion%' )
# SELECT "posts"."id", "posts"."created_at" FROM
"posts" INNER JOIN "comments" ON ("posts"."id" =
"comments"."post_id") WHERE ("comments"."email" LIKE
'contagion%') ORDER BY "posts"."id"
12
13. Go off the Golden Path
repository(:default).adapter.resource_naming_convention =
DataMapper::NamingConventions::Resource::Underscored
class Stock
property :target_symbol, String, :key => true
property :target_type_id, String, :key => true
repository(:legacy) do
property :target_name, String
end
end
Custom Naming Convention
Composite Keys
Multiple databases
13