Results 1 to 2 of 2

Thread: Need help understanding Ext.data.association

  1. #1
    Sencha User
    Join Date
    May 2012
    Location
    Weed, CA, US
    Posts
    18
    Answers
    2
    Vote Rating
    1
      0  

    Default Need help understanding Ext.data.association

    Reading the docs like http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.association.BelongsTo leaves me confused. I do not understand what an "owner" Model is in ExtJS4. I also do not understand in which model to define the Ext.data.association.*.

    I've got a backend with tables like this:
    Code:
    BEGIN;
    CREATE TABLE "Assessor_question" (
        "id" integer NOT NULL PRIMARY KEY,
        "text" text NOT NULL
    )
    ;
    CREATE TABLE "Assessor_choice" (
        "id" integer NOT NULL PRIMARY KEY,
        "text" text NOT NULL,
        "is_correct" bool NOT NULL,
        "question_id" integer NOT NULL REFERENCES "Assessor_question" ("id")
    )
    ;
    CREATE TABLE "Assessor_quiz" (
        "id" integer NOT NULL PRIMARY KEY,
        "user_id" integer NOT NULL REFERENCES "auth_user" ("id"),
        "num_questions" integer unsigned NOT NULL,
        "num_correct" integer unsigned NOT NULL
    )
    ;
    CREATE TABLE "Assessor_quizquestion" (
        "id" integer NOT NULL PRIMARY KEY,
        "quiz_id" integer NOT NULL REFERENCES "Assessor_quiz" ("id"),
        "question_id" integer NOT NULL REFERENCES "Assessor_question" ("id")
    )
    ;
    COMMIT;
    Then there are my models:
    Code:
    Ext.define('Assessor.model.Question', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'int'},
            {name: 'text', type: 'string'},
            {name: 'resource_uri', type: 'string'}
        ],
        proxy: {
            type: 'rest',
            url: '/api/v1/question/',
            headers: {
                'accept':'application/json',
                'content-type':'application/json'
            },
            noCache: false,
            reader: {
                type: 'json',
                root: 'objects',
                idAttribute: 'id'
            },
            writer: {
                type: 'json'
            }
        }
    })
    
    Ext.define('Assessor.model.Choice', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'int'},
            {name: 'question', type: 'string'}, //fk(Question)
            {name: 'text', type: 'string'},
            {name: 'is_correct', type: 'boolean'},
            {name: 'resource_uri', type: 'string'}
        ],
        proxy: {
            type: 'rest',
            url: '/api/v1/choice/',
                headers: {
                'accept':'application/json',
                'content-type':'application/json'
            },
            noCache: false,
            reader: {
                type: 'json',
                root: 'objects',
                idAttribute: 'id'
            },
            writer: {
                type: 'json'
            }
        }
    })
    
    Ext.define('Assessor.model.QuizQuestion'), {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'int'},
            {name: 'quiz', type: 'int'},
            {name: 'question', type: 'int'},
            {name: 'resource_uri', type: 'string'}
        ],
        proxy: {
            type: 'rest',
            url: '/api/v1/quizquestion/',
            headers: {
                'accept':'application/json',
                'content-type':'application/json'
            },
            noCache: false,
            reader: {
                type: 'json',
                root: 'objects',
                idAttribute: 'id'
            },
            writer: {
                type: 'json'
            }
        }
    }
    
    <etc...>
    The models load their primary data well. All I need is an example of how the Models associate. Many thanks.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,385
    Answers
    3997
    Vote Rating
    1540
      0  

    Default

    The owner model is the model that is being belonged to. So modelA belongs to modelB, modelB would be the owner.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •