1. #1
    Touch Premium Member
    Join Date
    Sep 2011
    Posts
    2
    Vote Rating
    0
    joylab is on a distinguished road

      0  

    Default How to read, save, update, destory (CRUD) models with associations in ExtJs4

    How to read, save, update, destory (CRUD) models with associations in ExtJs4


    Wouldn't you love to know how to do this?
    Don't you expect this to be straightforward?

    Please share your answers (including you Sencha) on how we're supposed to do this.

    I see lots of "hacks" and work-arounds but I can't seem to find the official answer and would love to know it.

    So apart from defining the associations in the model, how to the stores communicates (including if your'e using Direct) - i.e. are the associations supposed to be retrieved from one store, or if each model has a store the store can fetch the required data?

    Please clarify how this works with an example, showing the json responses from the server.

    A simple example would consist of a grid, that reads, saves, updates and deletes records where the records are composed from an *association* of tables.

  2. #2
    Sencha User
    Join Date
    Oct 2011
    Location
    Vancouver, Canada
    Posts
    157
    Vote Rating
    14
    el_chief will become famous soon enough

      1  

    Default


    I am not sure what you mean by "how do the stores communicate"? What sort of communication are you asking about?

    I am not sure how you would represent a belongsTo, hasOne, and hasMany relationships in a single grid. That really doesn't make any sense. Please clarify your question.

    In the meantime, you should read:

    Rules for HasOne and BelongsTo Associations

    Rules for HasMany Associations

    You should also decide if you are talking about nested loading (related data in the same response), or demand loading (make a new request when desired).

    Sencha does not want people to use nested writing for some reason, which is why they hid the functionality. It's doable though. If you clarify your question, I will show you how.

  3. #3
    Touch Premium Member
    Join Date
    Sep 2011
    Posts
    2
    Vote Rating
    0
    joylab is on a distinguished road

      0  

    Default


    Thanks @el_chief,

    My rant primarily has to do with "not enough clarifications" from Sencha as a paid library.

    E.g. your links go to your blog with explanations, etc.. (which is great - but I'd love the story straight from the horses' mouth)

    Having said that:

    What's the use case in a grid?

    You have Person Model that has One Address Model, I want to pull that relevant data and display it in the same row (as the same record) in a grid; e.g. each Person with their associated Address;

    If the Person hasMany Numbers, I might want to also have access to that data in the grid display (for example using those "expanding rows" in the grid and dump extra hasMany data here)

    The big question is - if I update any of those records (Person field, or Address), how does that data get pushed back? (and how much work does the framework do + do we have to manually handle)

    Initially, I thought that since each Model has defined proxy / API CRUD (e.g. using Direct to specify create, update, read, destroy api methods) that the associations would call those respective methods when operations are taking place on the associated data;

    i.e. Save Person uses the save Direct api method; the associated address (since the association is defined) uses the Address save Direct api method, etc.. <-- is this how its supposed to work? or should e.g. the Save Person Direct api method also handle receiving the associated data of Address Model in the backend? <-- This is not clear to me/thanks for clarifying;

    I find that this can lead to confusion on what defining associations brings to the table really and specifically what is the implementation on Extjs's side.

    Thanks for any clarifications? I often wonder if I'm e.g. under-using the power of the library - and not sure if its because a) that part of it is simply broken/best no use it - or I dont' understand how to use it (could be both)

Thread Participants: 1

Tags for this Thread