Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Commit c6f59bd

Browse files
committed
Add a Common Pitfalls section to the docs
1 parent 36f29b2 commit c6f59bd

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ created_at: Fri Nov 30 15:29:01 +1030 2007
3333
<dd>Paranoia, Timezone Handling, Single Table Inheritance, and Multiple Repositories.</dd>
3434
<dt><a href="/docs/legacy.html">Working with Legacy Schemas</a></dt>
3535
<dd>Adapting data-store naming conventions to your own property names.</dd>
36+
<dt><a href="/docs/pitfalls.html">Common Pitfalls</a></dt>
37+
<dd>Solutions and work-arounds to common problems.</dd>
3638
<dt><a href="/docs/dm_more/">More</a></dt>
3739
<dd>Plugins galore for DataMapper.</dd>
3840
</dl>

docs/pitfalls.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
layout: default
3+
title: Commom Pitfalls
4+
body_id: docs
5+
created_at: Sun Apr 01 21:13:13 -0700 2012
6+
---
7+
8+
{{ page.title }}
9+
================
10+
11+
Below is a list of common problems that someone new to DataMapper will
12+
encounter, along with work-arounds or solutions if possible.
13+
14+
Implicit String property length
15+
-------------------------------
16+
17+
When declaring a String property, DataMapper will add an implicit length of 50
18+
characters if nothing is explicitly declared.
19+
20+
For example, the two class declarations have identical behaviour:
21+
22+
{% highlight ruby linenos %}
23+
# with an implicit length
24+
class Post
25+
include DataMapper::Resource
26+
27+
property :title, String
28+
end
29+
{% endhighlight %}
30+
31+
{% highlight ruby linenos %}
32+
# with an explicit length
33+
class Post
34+
include DataMapper::Resource
35+
36+
property :title, String, :length => 50
37+
end
38+
{% endhighlight %}
39+
40+
The reason for this default is that DataMapper needs to know the underlying
41+
column constraints in order to add validations from the property definitions.
42+
Databases will often choose their own arbitrary length constraints if one is not
43+
declared (often 255 chars). We choose something a bit more restricted as a
44+
default because we wanted to encourage peolpe to declare it explicitly in their
45+
model, rather than relying on DM or the DB choosing an implicit limit.

0 commit comments

Comments
 (0)