1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    12
    Vote Rating
    1
    deanmoses is on a distinguished road

      0  

    Default Many to Many model example

    Many to Many model example


    I've read in the forums that you implement a many-to-many relationship with two hasMany associations.

    However, Ext 4's hasMany documentation shows the hasMany association looking for a single ID field on the other model, when in fact you'll need an array of IDs. Example:
    Code:
    Ext.define('Product', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id',      type: 'int'},
            {name: 'category_id', type: 'int' /* needs to be array of ints */ },
            {name: 'name',    type: 'string'}
        ],
        hasMany: {model: 'Category', name: 'categories'}
    });
    
    Ext.define('Category', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id',   type: 'int'},
            {name: 'product_id', type: 'int' /* needs to be array of ints */ },
            {name: 'name', type: 'string'}
        ],
        hasMany: {model: 'Product', name: 'products'}
    });
    What do the models really look like in a many-to-many scenario?

    Thanks!

  2. #2
    Ext JS Premium Member jason.hutton's Avatar
    Join Date
    Nov 2010
    Location
    Birmingham, AL
    Posts
    7
    Vote Rating
    0
    jason.hutton is on a distinguished road

      0  

    Default Same problem here

    Same problem here


    How would you implement this in a MVC application? The sync() method ignores my association...
    Jason Hutton

    I see your schwartz is as big as mine!

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    12
    Vote Rating
    1
    deanmoses is on a distinguished road

      0  

    Default


    Jason, I never figured out many-to-many associations -- gave up and used a different product.

  4. #4
    Ext JS Premium Member jason.hutton's Avatar
    Join Date
    Nov 2010
    Location
    Birmingham, AL
    Posts
    7
    Vote Rating
    0
    jason.hutton is on a distinguished road

      0  

    Default Working on solution

    Working on solution


    I am working to find a solution. If you are interested I will post it back here?

    Also, the Sencha devel team said they do not currently support the sync() of associated data as stated here.
    Jason Hutton

    I see your schwartz is as big as mine!

  5. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    12
    Vote Rating
    1
    deanmoses is on a distinguished road

      0  

    Default


    Absolutely! Ext's pretty sweet in most regards, would love to give it a second chance.

  6. #6
    Sencha User
    Join Date
    Aug 2011
    Posts
    33
    Vote Rating
    2
    tonyx is on a distinguished road

      0  

    Default


    I've been looking around for a solution to this problem for a while now. Basically it looks like ManyToMany is simply not natively supported by Ext Js. The only solution I found so far that gives a workaround is discussed on this blog page

    http://wintermedia-extjs.blogspot.co...sionships.html

    Basically it recommends creating 3 models for many to many, one used exclusively for just linking. At this point, rather than being a full object model, it seems to me Ext Model has more resemblance to SQL tables.

  7. #7
    Sencha User Izhaki's Avatar
    Join Date
    Apr 2009
    Location
    London
    Posts
    118
    Vote Rating
    13
    Izhaki will become famous soon enough

      1  

    Default


    I've posted an answer for this with some code example here.

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

      1  

    Default


    There are two ways:

    1. Use a hasMany relationship, and do work on the server to convert it to/from a manyMany relationship

    Customer -< Orders

    2. Use two hasMany relationships, ie:

    Customer -< CustomerOrder >- Order

    I prefer #2 as we often have extra info in our junction tables that we need to use anyways

  9. #9
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Vote Rating
    0
    pflopez is on a distinguished road

      0  

    Default


    I'm doing the Customer -< CustomerOrder >- Order method , but having a hard time saving the data (json/rest) of the order.

    So far, what I'm doing (and believe me, it's awful ), it's saving the Order, and on the save callback, save each customerOrder.

    The problem with this is that I'll end up having n+1 requests, n being the number or CustomerOrder items.

    How can I save the order all in one request?

    Thanks!


film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar