datamapper/dm-core — Issue #184: Invalid date in legacy database
Author: dgmdan
Created: 2012-02-15 23:02:20+00:00
State: open

I'm using DM to access a legacy MySQL database. One of the datetime columns frequently has values of 0000-00-00 00:00:00. When DM encounters one of these, I get an "invalid date" error. I would like to gracefully handle it instead. Here's the code that causes the error:

```
class UserProfile
include DataMapper::Resource
storage_names[:default] = 'subscriber_profile'

belongs_to :user, key: true
belongs_to :school, key: true

property :profile_start, DateTime
property :profile_end, DateTime

def self.active
all(
:profile_start.lt => Time.now,
:profile_end.gt => Time.now
)
end
end
```
When I call ```UserProfile.active```, it finds some of records with zeros for "profile_end" and gives the error. I would like to exclude these records altogether because if it has a profile_end of zeros, it's not an "active" record anyway.