Prev: check Fixnum
Next: Looking for some documentation.
From: Martin DeMello on 15 Jun 2010 12:29 I'm investigating the use of DataMapper to convert an old project with handwritten sql into something a bit more maintainable. Writing the model mappings etc. was quick and easy, then I ran into the following issue: I had a field defined as a timestamp in postgresql, and the old code was passing it a string in the insert statement. I accidentally passed the string to DataMapper, so I had something like model.new(:name => foo, :modified => datestring) instead of model.new(:name => foo, :modified => date) The problem was that DataMapper simply returned false when I tried saving it, with no indication of what had failed. Turning on verbose sql logging revealed that it didn't even attempt to create the INSERT statement (which is fair enough). It took me roughly an hour to discover my mistake. I then spent another hour poking around the DM documentation and API, searching for the debugging technique that would have let me catch my original mistake quickly and easily, and have come up blank. Is DataMapper really that unhelpful, or am I doing something wrong? Is Sequel any better in this regard? If I do switch to Sequel, is the model support as good as DataMapper's? martin
From: Dan Kubb on 15 Jun 2010 13:14 Martin, You want to make sure you require dm-validations. If you check object.errors you should see all the errors in the object reported. DataMapper reflects on the model definition you provide and sets up validations for all the properties. If you were just using dm-core, you're only pulling in one piece of the ORM that handles persistence. DataMapper's pieces are decoupled so that you only require what you need. There is a datamapper metagem that pulls in the default "stack" for you, and will include dm-validations among other plugins. Dan --- frmsrcurl: http://compgroups.net/comp.lang.ruby/datamapper-blues
From: Martin DeMello on 15 Jun 2010 13:52 On Tue, Jun 15, 2010 at 10:45 PM, Dan Kubb <user(a)compgroups.net/> wrote: > Martin, > > You want to make sure you require dm-validations. If you check object.errors you should see all the errors in the object reported. DataMapper reflects on the model definition you provide and sets up validations for all the properties. Thanks, that caught it. Still doesn't show up in the traceback when I turn raise_on_save_failure on, I'll file an enhancement request for that. martin
From: Dan Kubb on 15 Jun 2010 15:55 Richard, > In practice I have found it a challenge to make DataMapper conform to legacy schema, and error feedback was limited. This is great feedback to have, and precisely the kind of information I need in order to improve DataMapper. Now that DM 1.0 is out, and the API is stable, DM is shifting the focus a bit. One of the primary areas I want to improve is legacy schema mapping, since I think that's a bigger issue than we'd like to admit in the ruby world. Most projects are not beautiful "green field" apps. Almost every company has legacy systems that sit in the corner, and programmers dread having to work on them. They would love to use ActiveRecord with the schema and talk to it using ruby, except AR makes too many assumptions about the schema. Even if it does work, the 1:1 mapping of columns to attributes can make for some ugly ruby code. As the maintainer of DataMapper I want to help solve this problem, or at least make it less painful. Even if we partially solve it and someone else extends that work I'm cool with that too. At the very least I am going to give it a good try. There are *so* many developers who would love to use Ruby, but aren't able to because the more "mainstream" tools don't work for them. Richard, I would love to hear more about the problems you ran into using DM with a legacy DB, whether it's here or on the datamapper mailing list. -- Dan --- frmsrcurl: http://compgroups.net/comp.lang.ruby/datamapper-blues
From: Martin DeMello on 15 Jun 2010 16:08
On Wed, Jun 16, 2010 at 1:30 AM, Dan Kubb <user(a)compgroups.net/> wrote: > > Now that DM 1.0 is out, and the API is stable, DM is shifting the focus a bit. One of the primary areas I want to improve is legacy schema mapping, since I think that's a bigger issue than we'd like to admit in the ruby world. That's great to hear. I love the looks of DM's ORM stuff, and would like to continue working with it if its legacy db support improves. martin |