1
1
---
2
2
layout : default
3
- title : Commom Pitfalls
3
+ title : Common Pitfalls
4
4
body_id : docs
5
5
created_at : Sun Apr 01 21:13:13 -0700 2012
6
6
---
@@ -14,32 +14,29 @@ encounter, along with work-arounds or solutions if possible.
14
14
Implicit String property length
15
15
-------------------------------
16
16
17
- When declaring a String property, DataMapper will add an implicit length of 50
18
- characters if nothing is explicitly declared.
17
+ When declaring a String property, DataMapper will add an implicit limit of 50
18
+ characters if no limit is explicitly declared.
19
19
20
20
For example, the two class declarations have identical behaviour:
21
-
22
21
{% highlight ruby linenos %}
23
22
# with an implicit length
24
23
class Post
25
24
include DataMapper::Resource
26
25
27
26
property : title , String
28
27
end
29
- {% endhighlight %}
30
28
31
- {% highlight ruby linenos %}
32
29
# with an explicit length
33
30
class Post
34
31
include DataMapper::Resource
35
32
36
33
property : title , String, : length => 50
37
34
end
38
35
{% endhighlight %}
39
-
40
36
The reason for this default is that DataMapper needs to know the underlying
41
37
column constraints in order to add validations from the property definitions.
42
38
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.
39
+ declared (often defaulting to 255 chars). We choose something a bit more
40
+ restrictive as a default because we wanted to encourage peolpe to declare
41
+ it explicitly in their model, rather than relying on DM or the DB choosing
42
+ an arbitrary limit.
0 commit comments