Results 1 to 10 of 10

Thread: Model error "Uncaught Error: Invalid record id returned..."

  1. #1
    Sencha Premium Member CSchmitz81's Avatar
    Join Date
    Nov 2012
    Location
    Saint Louis
    Posts
    118
    Answers
    6

    Default Model error "Uncaught Error: Invalid record id returned..."

    I'm grappling with a demo project I'm using to understand mvvm.

    Right now I have a Model that has a proxy config that pulls json data. I have a grid view who's ViewController listens to the cell click event. The method called on the cell click:
    • Gets a form panel class (separate view I've defined)
    • Gets the form panel's viewModel
    • Fires the linkTo method to link a reference of the model using the record ID from the grid row clicked
    I had this kind of working before after getting help on a separate sencha forum thread, but I was only ever able to load the first record from my json (i.e. regardless of what row I clicked, only the first record's data would display in the form panel).

    Here's the controller:

    Code:
    Ext.define('CoolPets2.view.petlist.PetListController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.petlist-petlist',
    
    
        onCellClick: function (table, td, cellIndex, record, tr, rowIndex, e, eOpts){
            debugger;
            var view = Ext.getCmp('petDetailsPanel');
            var viewmodel = view.getViewModel();
    
    
            viewmodel.linkTo('Pet',{
                reference: 'CoolPets2.model.Pets',
                id: record.id
            });
        }
        
    });
    And here's the data that it's pulling through the model:

    Code:
    {
        'pets':[
            {id: 1, name: 'Madori', type: 'cat', age: 10, img: '/data/petpics/madori.jpg'},
            {id: 2, name: 'Zoe', type: 'dog', age: 5, img: '/data/petpics/zoe.jpg'},
            {id: 3, name: 'Petey', type: 'dog', age: 2, img: '/data/petpics/petey.jpg'},
            {id: 4, name: 'Dillon', type: 'turtle', age: 9, img: '/data/petpics/dillon.jpg'},
            {id: 5, name: 'Heather', type: 'turtle', age: 9, img: '/data/petpics/heather.jpg'},
        ]
    }


    When the `viewmodel.linkTo()` method above fires for a particular gridpanel row (say row 3), I get a console error "Uncaught Error: Invalid record id returned for [email protected]".

    When referring back to the documentation section on Record Binding it looks like I somehow need to include a session object in my code (though it doesn't explain how). I read up on Ext.data.Session in the API docs and I get what the session is doing (at least I assume I do), but I can't seem to find an example of how I would implement it in this case.

    If anyone could help me figure out how to get over this wall I would appreciate it, and if anyone could point me in the right direction in the documentation as far as where to read up on the proper way of doing this kind of a structure using MVVM I would greatly appreciate it. I'm having a hard time finding good/clear/complete explanations for a beginner.

  2. #2
    Sencha User
    Join Date
    Jun 2008
    Posts
    242
    Answers
    22

    Default

    record.id does not appear in the api docs. Have you tried record.getId()?

  3. #3
    Sencha Premium Member CSchmitz81's Avatar
    Join Date
    Nov 2012
    Location
    Saint Louis
    Posts
    118
    Answers
    6

    Default

    I just tried switching the code to use record.getId() instead of record.id. It pulls the same value and gives the same error :/

  4. #4
    Sencha User
    Join Date
    Jun 2008
    Posts
    242
    Answers
    22

    Default

    what does the reply from the server look like when you do linkTo?

    edit: do you have a fiddle? now i see it should not be going to the server since that data should already be in the session but that error is in response to a server request.

    edit2: looking at your other code, the lack of a common session between your grid and your details is likely the problem. set session: true at the container that holds the grid and the detail view. at that point both the children should have access to the same session

  5. #5
    Sencha Premium Member CSchmitz81's Avatar
    Join Date
    Nov 2012
    Location
    Saint Louis
    Posts
    118
    Answers
    6

  6. #6
    Sencha Premium Member CSchmitz81's Avatar
    Join Date
    Nov 2012
    Location
    Saint Louis
    Posts
    118
    Answers
    6

  7. #7
    Sencha User
    Join Date
    Jun 2008
    Posts
    242
    Answers
    22

    Default

    So whats happening here is that your linkTo call on the detail is looking into it's session and it cannot find the record as it is a different session than the grid. It then goes to the server and tries to get it (see id = 3?) but the server returns a whole bunch of records that are not record #3. Its yelling because it asked the server for 3 and got 1 - 5.


    To fix this you either pass the record itself as data to the view model, or you make sure the session of the detail is the same as the grid so they can share records via linkTo.

  8. #8
    Sencha Premium Member CSchmitz81's Avatar
    Join Date
    Nov 2012
    Location
    Saint Louis
    Posts
    118
    Answers
    6

    Default

    Ah! That totally makes sense!

    I can't dig into it now, but as soon as I get home I'll make the adjustment.

    Thank you very much. That clears up a lot of misunderstandings for me.

  9. #9

  10. #10
    Sencha Premium Member CSchmitz81's Avatar
    Join Date
    Nov 2012
    Location
    Saint Louis
    Posts
    118
    Answers
    6

    Default

    Perfect, thanks!!

Similar Threads

  1. Replies: 11
    Last Post: 17 Sep 2014, 2:24 PM
  2. Replies: 1
    Last Post: 16 Sep 2014, 11:05 AM
  3. Replies: 2
    Last Post: 23 Jan 2014, 9:32 PM
  4. Replies: 8
    Last Post: 27 Aug 2012, 11:37 PM

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
  •