1. #1
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    2
    tkolo is on a distinguished road

      0  

    Default Answered: Store syncing non-phantom records

    Answered: Store syncing non-phantom records


    I'm wondering about syncing non-phantom records.
    Let's say that we have a non-phantom, non-modified model (a phantom = false, fresh brand new record just fetached from database), and some other model with HasMany relation.
    Now we add that model into the relation's store, and then sync it. Will that model get send? What I've seen in code, store uses three methods to get record arrays to sync: getNewRecords(), getUpdatedRecords() and getRemovedRecords().

    getNewRecords() returns all models that are valid and have phantoms set to ture, so not ours, unless store sets it on add, but i haven't noticed such thing.
    getUpdatedRecords() returns all models that are dirty, not phantom and valid, so also not ours as it was never modified.
    getRemovedRecords() returns all models from store's removed array, so also not ours as it was never removed from that store.

    And so, does that mean the model will never get synced with server? Or am I missing something?

  2. No the information is not lost, you will have to update the foreignKey, in this case the addressId (or what ever) of the person. Since then it becomes dirty (id changed) and the store knows that there was a change.

  3. #2
    Sencha User
    Join Date
    Jul 2012
    Posts
    33
    Answers
    4
    Vote Rating
    4
    Alexander Bauer is on a distinguished road

      0  

    Default


    If your model was not modified, why would you want to push traffic to your backend? There is no new information for the backend which would be "worth" to store it.

    If you say
    Now we add that model into the store
    , it becomes a new entry to the store, since it was not there before and will be send to the backend for synching.

  4. #3
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    2
    tkolo is on a distinguished road

      0  

    Default


    Hi Alexander,

    Thanks for replying!
    First of all, yes, there is information "worth storing", in the backend, it's the fact that the relation appeared.
    Imagine a Person object having many Addresses, and that we have pull of Adresses already defined (as store of them on client side let's say). Now you assign a new (but already existing!) address to our Person and sync it. Both objects already exsited in database, the new thing here is the relation, which is new, but still, very important information.
    You're right though, i mentioned only the store part, while I was actually thinking about HasMany relation, sorry for that, will fix my post now.

    Now You said that "it becomes new to the store". How? As far as i've seen, it's not marked anywhere as "a new in store" record, it seems that this information is simply getting lost.
    What I'm asking for if is the above sentence true? Is that information really lost?
    Last edited by tkolo; 4 Dec 2012 at 9:06 AM. Reason: I was wrong a bit

  5. #4
    Sencha User
    Join Date
    Jul 2012
    Posts
    33
    Answers
    4
    Vote Rating
    4
    Alexander Bauer is on a distinguished road

      1  

    Default


    No the information is not lost, you will have to update the foreignKey, in this case the addressId (or what ever) of the person. Since then it becomes dirty (id changed) and the store knows that there was a change.

  6. #5
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    2
    tkolo is on a distinguished road

      0  

    Default


    I don't have foreignKey nor any other field in related model that'd change upon binding it with relation owner. My backend uses object-oriented database, what matters is relation.

  7. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    33
    Answers
    4
    Vote Rating
    4
    Alexander Bauer is on a distinguished road

      0  

    Default


    Then the reference/pointer to an object should change, which is not equal to the last one and becomes dirty?

  8. #7
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    2
    tkolo is on a distinguished road

      0  

    Default


    Not sure what you mean. This is javascript, what... pointer?

  9. #8
    Sencha User
    Join Date
    Jul 2012
    Posts
    33
    Answers
    4
    Vote Rating
    4
    Alexander Bauer is on a distinguished road

      0  

    Default


    var obj1 = {};
    var obj2 = {};
    obj1 === obj1 // true
    obj1 === obj2 // false

    they both are empty objects (equal) but the reference differs and therefore they are not the same.

    In your database, how do you map an address to a person, so you can get the associated address of person x?
    Somehow person needs to know which address is belonging to it, whether it is an id or an object?

  10. #9
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    2
    tkolo is on a distinguished road

      0  

    Default


    I have no idea how it exactly happens on the backend server, as here I am only javascript (forntend) developer. Given the Person-Address example, they want it sent like this:
    Code:
    {    "Name": "whatever",
        "Surname": "whatever2",
        "Addresses": [
            {
                "street": "...",
                ...
            }
        ]
    }
    which i already accomplished. My question still remains, how can I detect the change in relation? I guess that Sehncha developers had similar approach as You have, they rely on foreignKey. I guess I need override then...
    Last edited by tkolo; 4 Dec 2012 at 9:44 AM. Reason: reformatted json

  11. #10
    Sencha User
    Join Date
    Jul 2012
    Posts
    33
    Answers
    4
    Vote Rating
    4
    Alexander Bauer is on a distinguished road

      0  

    Default


    As far as I know you cannot store hasMany directly in a store.
    Using methods like

    Code:
    person.getAddress(function(addressObject) {
       // ...
    });
    will simply call a foreign model to load (if not already did) the corresponding address object from the backend.
    I am afraid you are right, I had similar issue using JSON-RPC and oAuth 2.0, which required me to extend several classes but fortunately the core extjs is solid and easy to extend (mostly).

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi