drogus / bulk_api

MIT License
149 stars 7 forks source link

What is _storeKey and do I need to care? #9

Closed drnic closed 13 years ago

drnic commented 13 years ago

Do my resource models need to have _storeKey columns in their tables? If a model is created outside of SproutCore, is a _storeKey created for it when it is sent to SproutCore via /api/bulk?

aflatter commented 13 years ago

Nope they don't have to. storeKey is an identifier that is used internally by SC.DataStore. As you do not need to immediately send a new sproutcore record to the server, the storeKey is used as long as the record is not persisted. On create, the server will include this key in the response and thus the data source can keep track.

Disclaimer: The above might not be totally accurate but explains the idea. ;) Still got to dig deeper today.

drogus commented 13 years ago

@aflatter got it right - it should be sent only on create to allow to identify records that were sent to server. As we don't have id yet, we need some other way to save that.

drogus commented 13 years ago

And actually it's _local_id now :)

Take a look at that example from README:

  def create(records)
    # records is an array of hashes with data that will be used
    # to create new records e.g.:
    # [{:title => "First", :done => false, :_local_id => 1},
    #  {:title => "", :done => true, :_local_id => 3}]
    # _local_id is needed to identify the records in sproutcore
    # application, since they do not have an id yet

    collection = super(records)

    collection
  end