Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

return value for Adapter#create #200

Open
hhuang opened this issue May 16, 2012 · 0 comments
Open

return value for Adapter#create #200

hhuang opened this issue May 16, 2012 · 0 comments

Comments

@hhuang
Copy link

hhuang commented May 16, 2012

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant