When submitting forms that include foreign-key values (foo_id=1), DataMapper is unable to coerce an empty String (the default value of a form field) to nil. Instead, DataMapper complains that the foreign-key must be nil or an Integer. As a work-around, I use this monkey-patch to DataMapper::Property::Integer:
# filters out empty Strings for properties that allow nil
unless (allow_nil? && value.blank?)
See also: datamapper/dm-rails#27
Agreed, this really caused me a headache when trying to implement optional associations.
typecast_to_primitive is removed from DataMapper 1.3.
dm-core said it's not a core issue and they were going to fix that on dm-rails but it looks like nothing has happened with it. Perhaps we should ask there again?
Are we protected from mass assignment in any way? These issues should be resolved together.
Should we plan this for 1.0 or close as #905 is there to protect from mass assignment. I think disallowed params should be deleted and good ones cast to integers or nils.
Good call @ujifgc. Rescheduled it for 1.0.
Closing in favor of #1524.
Also you can use params protection to typecast foreign keys:
post :update, :params => [:name, :foreign_model_id => Integer] do
@ujifgc too cool!