return value for Adapter#create #200

hhuang opened this Issue May 16, 2012 · 0 comments

1 participant


I'm in the midst of building out an adapter for data mapper and am running into an issue where create reports that a save is successful even though the save failed.

according to the documentation in abstract adapter, create should return the number of records that were actually saved to the datastore. however, this value is ignored and the save is assumed to be succesful as long as the attributes on the DataMapper::Resource are valid at the time it is to be persisted.

this is the block of code in question:

def commit
    return self unless valid_attributes?

create_resource eventually calls the adapter's create method but this value is discarded. so in the case that the create fails, it still reports back as saving successfully.

i'd assumed that the return value was so that you could check that all records were successfully persisted. you could raise an exception from the adapter, but that seems pretty heavy-handed.

what would the "data_mapper" of handling this situation be? perhaps, returning the transient persistence state or another persistence state to indicate the create had failed but would allow for a normal retry as desired?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment