Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (47 sloc) 2.23 KB
=== So where's my :id column?
DataMapper will NOT create an auto-incrementing <tt>:id</tt> key for you
automatically, so you'll need to either explicitly create one with
property :id, Serial
You can choose to use a natural key by doing
property :slug, String, :key => true
Remember, DataMapper supports multiple keys ("composite keys"), so if your
model has two or more keys, no big deal
property :store_id, Integer, :key => true
property :invoice_id, Integer, :key => true
=== How do I make a model paranoid?
Create a property and make it a ParanoidDateTime or ParanoidBoolean type.
property :deleted_at, ParanoidDateTime
property :deleted, ParanoidBoolean
All of your calls to <tt>##all()</tt>, <tt>##first()</tt> will be scoped
with <tt>:deleted_at => nil</tt> or <tt>:deleted => false</tt>. Plus,
you won't see deleted objects in your associations.
=== Does DataMapper do Single Table Inheritance?
This is what the Discriminator data-type is for:
class Person
include DataMapper::Resource
property :id, Serial
property :type, Discriminator ## other shared properties here
class Salesperson < Person; end
You can claim a column to have the type <tt>Discriminator</tt> and DataMapper will
automatically drop the class name of the inherited classes into that field of
the data-store.
=== How do I run my own commands?
repository.adapter.query("select * from users where clue > 0")
repository(:integration).adapter.query("select * from users where clue > 0")
This does not return any Users (har har), but rather Struct's that will quack
like Users. They'll be read-only as well.
<tt>repository.adapter.query</tt> shouldn't be used if you aren't expecting a result set
back. If you want to just execute something against the database, use
<tt>repository.adapter.execute</tt> instead.
=== Can I get an query log of what DataMapper is issuing?
Yup, to set this up, do:, 0)
Incidentally, if you'd like to send a message into the DataMapper logger, do:
DataMapper.logger.debug { "something" } { "something" }
DataMapper.logger.warn { "something" }
DataMapper.logger.error { "something" }
DataMapper.logger.fatal { "something" }
Jump to Line
Something went wrong with that request. Please try again.