Changing default String length also changes default Text length

75 views
Skip to first unread message

gugod

unread,
Oct 10, 2010, 12:26:09 PM10/10/10
to DataMapper
Hi all,

Recently I changed the default string length from 50 to 255 with this:

DataMapper::Property::String.length(255)

However, that also effected Text properties and those properties
becomes a `tinytext` table fields. After reading property.rb a bit, I
realized that this seems to be coded on purpose -- all sub-classes of
DataMapper::Property::String has `length` option as a class method,
and changing the value of length on String will end up being
propagated to all is subclasses.

And then the work-around is to add another lines to reset default Text
length like this:

DataMapper::Property::String.length(255)
DataMapper::Property::Text.length(65535)

While this usage is not documented as the way to alter default length,
it seems to becomes a small problem that people might bump into from
time to time. Mainly because String has a very insufficient default
length of 50. A commonly used `email` or `title` field (of any sort of
model) can easily overflow that limit. People using ActiveRecord::Base
before will feel highly uncomfortable with that short length and
they'll want to change the default to be 255 if they figured out how.

It feels like the current coded behavior can benefit dm internally so
maybe they should not be changed. Because of that, I wonder if this
should be at least documented somewhere for reference. Or
alternatively, DataMapper should provide some sort of official
configure API (maybe like Rspec.configure) such that options in each
property classes can be individually tweaked.


Jonathan Stott

unread,
Oct 10, 2010, 3:51:10 PM10/10/10
to datam...@googlegroups.com
Hi gugod

I believe you've actually discovered a bug in dm-core. It's not
intended that options set in the way you did propagate down into
subclasses which have previously set their own value.

Regards
Jon

Piotr Solnica

unread,
Oct 10, 2010, 3:57:57 PM10/10/10
to DataMapper
As Jonathan wrote, you found a bug! It will be fixed in the next
release.

gugod

unread,
Oct 11, 2010, 5:12:03 AM10/11/10
to DataMapper
Alright then :D

I actually read a paragraph of rdoc latter in property.rb that
describe how it should've worked, which confused me a bit. But now
it's cleared :-)
Reply all
Reply to author
Forward
0 new messages