1. #1
    Sencha User
    Join Date
    Jul 2013
    Posts
    5
    Vote Rating
    0
    davidcfk is on a distinguished road

      0  

    Default Unanswered: HasOne Association: Getting property by foreignID

    Unanswered: HasOne Association: Getting property by foreignID


    Reposted: for some reason my other post died... (admin can you assist?)

    Does anybody know where I can find a good guide on how to do the following:

    I have a model that has these fields
    fields: [
    {name: 'workorder_id', type: 'int'},
    {name: 'type_id', type: 'int'},
    {name: 'category_id'},
    {name: 'subject', type: 'string'},
    {name: 'status_id', type: 'int'},
    {name: 'timecreated', type: 'string'},
    {name: 'timemodified', type: 'string'},
    {name: 'contact', type: 'string'},
    {name: 'submitter', type: 'string'},
    {name: 'responsible', type: 'string'}
    ]

    Some of which are just ID numbers of objects I want it to have (it's essentially a hasOne). So, I have placed HasOne relationships (I'll just put an example here):
    { type: 'hasOne', model: 'AppPortal.model.workorder.Category', name: 'category_id', associationKey: 'data', foreignKey: 'category_id', getterName: 'getCategory'}

    and it is meant to, when I have an instance of this Model I would be able to run something like:
    modelObj.getCategory().get('name')

    Assuming of course I have a Category object with the proxy set up that fetches the data etc.

    Right now, for some reason, the proxy only returns the first item name, regardless of what category_id that sits in the object (interestingly the raw data property seems to keep thinking the id is 1, so obviously the loading only seems to be taking the first one, rather than looking at the category_id).

    Anybody got an interesting idea on how I would be able to achieve getting the values?

  2. #2
    Sencha User
    Join Date
    Jul 2013
    Posts
    5
    Vote Rating
    0
    davidcfk is on a distinguished road

      0  

    Default Maybe one solution...

    Maybe one solution...


    Well after a lot of fuss I think I ended up just including a store in the controller, and then doing a lookup... I'll be using this snippet in the renderer for my grid display I suppose.

    Code:
         var store = Ext.data.StoreManager.lookup('workorder.Types');     return(store.getAt(store.find('type_id', value)).get('name'));

  3. #3
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    4,081
    Vote Rating
    69
    Answers
    157
    Gary Schlosberg has a spectacular aura about Gary Schlosberg has a spectacular aura about Gary Schlosberg has a spectacular aura about

      0  

    Default


    Glad to hear you found a solution. Your other thread was likely in moderation for a bit, but it was still around, until I deleted it a few minutes ago as a duplicate.

Thread Participants: 1