gugod
unread,Oct 10, 2010, 12:26:09 PM10/10/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.