Results 1 to 6 of 6

Thread: record.getAssociatedData does not work if association set with parent session record

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-18567 in 6.0.1.
  1. #1
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    19

    Default record.getAssociatedData does not work if association set with parent session record

    STAND-ALONE TESTCASE
    https://fiddle.sencha.com/#fiddle/q2r

    Ext version tested:

    • Ext 5.1.1 rev 451
    Browser versions tested against:
    • Chrome 43
    DOCTYPE tested against:
    • Strict
    Description:
    • When using the setter of an association on a record from a child session with a record from the parent session, Ext does not save the instance on the child record. This causes the method Ext.data.schema.Role#getAssociatedItem to return null. This is a problem when calling childRecord.getAssociatedData.

      My override just use deep=true for peeking rightRecord in Ext.data.schema.ManyToOne#onValueChange. There is probably a good reason for not using deep=true there, but I could'n figure it and it solves my problem.
    Steps to reproduce the problem:
    • open Fiddle and comment override
    The result that was expected:
    • childRecord.getAssociatedData returns the data for the associated record
    The result that occurs instead:
    • childRecord.getAssociatedData returns an empty object

  2. #2
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    It's not really intended that you be mixing records across sessions like that. I was going to put together an example of a better way to do it, however there isn't really a great API at this point for dealing with an instance like that.

    I was thinking something like:

    Code:
    user.load({
        callback: function() {
            var groupFromParentSession = user.getGroup();
            var childSession = session.spawn();
            var newUser = childSession.createRecord('User');
            newUser.setGroup(childSession.getRecord(groupFromParentSession));
        }
    });
    So getRecord changes to be able to accept a record instance. It would then basically behave the same as it does now, it will look up to the parent and pull down the appropriate copy as required. I think it's better to be explicit in this case than to have have it to magic under the scenes, because then the record instance you've just set will be transformed silently and they will no longer be equal.

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    19

    Default

    You're right. It is bad practice. Although in our case the record set is not intended to be modified. Only the reference is needed for getAssociatedItem to work when we save the record with our system for submitting nested data.

    I'm upgrading our app from 5.0.1 to 5.1.1 and it used to work in 5.0.1. The developers in my team are aware that they need to use getRecord when editing records in a child session. But they would just access records in another way when making sure the setters are called for the nested data to save correctly.

    So I reverted my override, added an import method to Ext.data.Session, will throw an error in dev from doSetFk, and silenlty import in prod until everything is fixed in dev: https://fiddle.sencha.com/#fiddle/q5o

    Thanks!

  4. #4
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Yes, I think some warning is in order if you do that.

    I prefer modifying getRecord() to accept a record instance as opposed to adding a new method, since getRecord already behaves in that way (looking up to the parent).

    So instead of:

    Code:
    session.getRecord(record.self, record.id);
    You could just pass:

    Code:
    session.getRecord(record);

  5. #5
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    19

    Default

    For updating Ext that could make sense to modify getRecord.

    The new importRecord method in my fiddle is just a simpler version of what it actually looks like in my app. It would be too much to add this logic to getRecord.

    As for making getRecord accept a record instance, what if the record is coming from an orphan session? Or if it has no session, but exists in the parent?

  6. #6
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    From an orphan session it will be an exception, once it goes into a session it can't participate elsewhere.

    If it has no session but exists in the parent, it will use the same copying behaviour as if you provided a the type/id.

Similar Threads

  1. [FIXED] Loading of OneToMany association with session does not work.
    By Hacker-CB in forum Ext 5: Bugs
    Replies: 3
    Last Post: 25 Mar 2015, 3:05 AM
  2. [DUP] Sync new record in association store duplicate the newly created record.
    By tradingpursuits in forum Sencha Touch 2.x: Bugs
    Replies: 4
    Last Post: 5 Feb 2015, 2:11 PM
  3. Session getSaveBatch and dropped record.
    By FunkySkywalker in forum Ext 5: Q&A
    Replies: 0
    Last Post: 10 Jul 2014, 11:56 PM
  4. setRecord(record) causing updaterecord(record)'s record to null
    By heisenburger in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 3 Dec 2013, 12:22 PM
  5. Remove Record and the Add Record doesn't work
    By izak18 in forum Sencha Touch 1.x: Q&A
    Replies: 1
    Last Post: 27 Apr 2012, 9:02 AM

Posting Permissions

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