Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 93 lines (58 sloc) 2.88 kB
e8b4f3b @sam Importing from old repository.
sam authored
1 :include:QUICKLINKS
2
3 = FAQ
4
6341058 rewriting docs for dm-point-nine
Adam French authored
5 === So where's my :id column?
e8b4f3b @sam Importing from old repository.
sam authored
6
6341058 rewriting docs for dm-point-nine
Adam French authored
7 DataMapper will NOT create an auto-incrementing <tt>:id</tt> key for you
8 automatically, so you'll need to either explicitly create one with
e8b4f3b @sam Importing from old repository.
sam authored
9
266988a Updated sepcs to use the Serial rather than Integer, :serial => true
Dan Kubb authored
10 property :id, Serial
e8b4f3b @sam Importing from old repository.
sam authored
11
6341058 rewriting docs for dm-point-nine
Adam French authored
12 You can choose to use a natural key by doing
e8b4f3b @sam Importing from old repository.
sam authored
13
6341058 rewriting docs for dm-point-nine
Adam French authored
14 property :slug, String, :key => true
e8b4f3b @sam Importing from old repository.
sam authored
15
6341058 rewriting docs for dm-point-nine
Adam French authored
16 Remember, DataMapper supports multiple keys ("composite keys"), so if your
17 model has two or more keys, no big deal
e8b4f3b @sam Importing from old repository.
sam authored
18
aac8ddb @somebee fixed some stuff in the FAQ
somebee authored
19 property :store_id, Integer, :key => true
20 property :invoice_id, Integer, :key => true
e8b4f3b @sam Importing from old repository.
sam authored
21
6341058 rewriting docs for dm-point-nine
Adam French authored
22 === How do I make a model paranoid?
e8b4f3b @sam Importing from old repository.
sam authored
23
6341058 rewriting docs for dm-point-nine
Adam French authored
24 Create a property and make it a ParanoidDateTime or ParanoidBoolean type.
e8b4f3b @sam Importing from old repository.
sam authored
25
6341058 rewriting docs for dm-point-nine
Adam French authored
26 property :deleted_at, ParanoidDateTime
27 property :deleted, ParanoidBoolean
e8b4f3b @sam Importing from old repository.
sam authored
28
6341058 rewriting docs for dm-point-nine
Adam French authored
29 All of your calls to <tt>##all()</tt>, <tt>##first()</tt> will be scoped
30 with <tt>:deleted_at => nil</tt> or <tt>:deleted => false</tt>. Plus,
31 you won't see deleted objects in your associations.
e8b4f3b @sam Importing from old repository.
sam authored
32
33 === Does DataMapper do Single Table Inheritance?
34
aac8ddb @somebee fixed some stuff in the FAQ
somebee authored
35 This is what the Discriminator data-type is for:
e8b4f3b @sam Importing from old repository.
sam authored
36
0ba594d @myabc Fixed Ruby 1.9 compatibility (use of : shorthand for 'then') in DataM…
myabc authored
37 class Person
38 include DataMapper::Resource
266988a Updated sepcs to use the Serial rather than Integer, :serial => true
Dan Kubb authored
39 property :id, Serial
aac8ddb @somebee fixed some stuff in the FAQ
somebee authored
40 property :type, Discriminator ## other shared properties here
e8b4f3b @sam Importing from old repository.
sam authored
41 end
42
43 class Salesperson < Person; end
44
8abb39e @somebee fixed a typo in FAQ
somebee authored
45 You can claim a column to have the type <tt>Discriminator</tt> and DataMapper will
6341058 rewriting docs for dm-point-nine
Adam French authored
46 automatically drop the class name of the inherited classes into that field of
47 the data-store.
e8b4f3b @sam Importing from old repository.
sam authored
48
49 === How do I run my own commands?
50
6341058 rewriting docs for dm-point-nine
Adam French authored
51 repository.adapter.query("select * from users where clue > 0")
52 repository(:integration).adapter.query("select * from users where clue > 0")
e8b4f3b @sam Importing from old repository.
sam authored
53
54 This does not return any Users (har har), but rather Struct's that will quack
55 like Users. They'll be read-only as well.
56
6341058 rewriting docs for dm-point-nine
Adam French authored
57 <tt>repository.adapter.query</tt> shouldn't be used if you aren't expecting a result set
e8b4f3b @sam Importing from old repository.
sam authored
58 back. If you want to just execute something against the database, use
6341058 rewriting docs for dm-point-nine
Adam French authored
59 <tt>repository.adapter.execute</tt> instead.
e8b4f3b @sam Importing from old repository.
sam authored
60
61
6341058 rewriting docs for dm-point-nine
Adam French authored
62 === Can I get an query log of what DataMapper is issuing?
e8b4f3b @sam Importing from old repository.
sam authored
63
77736bc Updated FAQ on logging
David James authored
64 An example of how to modify an existing logger:
e8b4f3b @sam Importing from old repository.
sam authored
65
77736bc Updated FAQ on logging
David James authored
66 DataMapper.logger.set_log(STDOUT, :debug)
e8b4f3b @sam Importing from old repository.
sam authored
67
77736bc Updated FAQ on logging
David James authored
68 An example of how to create new logger:
69
70 DataMapper::Logger.new(STDOUT, :info)
71
72 To send a message to the DataMapper logger:
73
74 DataMapper.logger.debug("something")
75 DataMapper.logger.info ("something")
76 DataMapper.logger.warn ("something")
77 DataMapper.logger.error("something")
78 DataMapper.logger.fatal("something")
e8b4f3b @sam Importing from old repository.
sam authored
79
f55fc12 Docs on giving custom socket for 'rake spec'
David James authored
80
81 === I want to run the specs, but I have a custom database setup
82
83 For example, if you installed MySQL using MacPorts, your socket may be located
84 at /opt/local/var/run/mysql5/mysqld.sock instead of /tmp/mysql.sock
85
86 In that case, setup an environment variable in your shell before running the
87 specs:
88 export MYSQL_SPEC_URI="mysql://localhost/dm_core_test?socket=/opt/local/var/run/mysql5/mysqld.sock"
89 rake spec
90
91 Using another kind of database? Note that spec_helper.rb will also look for
92 SQLITE3_SPEC_URI AND POSTGRES_SPEC_URI.
Something went wrong with that request. Please try again.