To determine what Orders are ready for delivery, it is good to have a scope that test two attributes. If an email exists (i.e. email is not null) and the customer has not been notified (i.e. date_customer_notified is null), then it can be reasonably inferred that an order is complete and awaits being delivered.
1 2 3 4 5
In order to store a copy of the email sent to the customer, we want to serilaize the email attribute so it can store natively a Ruby Mail object. However, there is a critical bug in all current versions of Rails that has only been updated on rails:master, but not in any released versions.
In order to accomplish our test of “email is not null”, we are presuming that the data in the underlying database is stored as NULL. (Wouldn’t it be nice if we could do something directly in rails like :email != nil, but I digress.) However, given current Rails implementation, the value of email in all new objects is an empty YAML string. Note the update query:
1 2 3 4 5
` Rails believes :email to be nil, but MYSQL knows differently so on the above Order object order.where(‘email is not null’) will never work. Therefore the necessary scope will always fail.
To solve this, I’ve cribbed from the master branch of Rails. Here is the commit.
In Tracksys, the local app, I’ve extended ActiveRecord to extend the YAMLColumn class.
1 2 3 4 5 6 7 8 9 10