Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

return value for Adapter#create #200

Open
hhuang opened this Issue · 0 comments

1 participant

hhuang
hhuang

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
    set_child_keys
    set_default_values
    return self unless valid_attributes?
    create_resource
    set_repository
    add_to_identity_map
    Clean.new(resource)  
end

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
Something went wrong with that request. Please try again.