1

我工作的一个项目是服务器站点是 Grails,客户端站点是 Extjs4.1,我使用关系数据库。在这种情况下,我工作正常,但是当我打电话给商店时,我遇到了一些问题。这个问题基于父母。当我像下面这样打电话给商店时......然后我必须打电话给它的父母,但我不想打电话给它的父母......

def stote(){        
    def prices = []
    Price.getAll()?.each{ v ->
        def a = v.article,
        b     = a.brand,
        bt    = b.brandType,
        gp    = b.genericProducts,
        c     = gp.categories,
        m     = b.manufacturers

        def manufacture     = [id:m.id,     name:m.name]
        def category        = [id:c.id,     name:c.name]
        def genericProduct  = [id:gp.id,    name:gp.name, m01i001001:category]
        def brandType       = [id:bt.id,    name:bt.name]
        def brand           = [id:b.id, name:b.name, m01i002001:manufacture, m01i003001:genericProduct, m01i004001:brandType]
        def article         = [id:a.id, name:a.name, mbcode:a.mbcode, pbcode:a.pbcode, details:a.details, m01i005001:brand]
        def price           = [id: v.id, m01i006001:article, price:v.price, date:v.date]
        prices << price
    }
    return prices
}

这些属于关联键 m01i001001, m01i002001, m01i003001,m01i004001,m01i005001,m01i006001

我的归属喜欢

 belongsTo : [{
  model          : '${pkgName}.M01I005001',
  associatedName : 'M01I005001' ,
  associationKey : 'm01i005001' , 
  primaryKey     : 'id' , 
  foreignKey     : 'brandId'     
}],

我想像这家商店一样打电话...

def stote(){        
    def prices = []
    Price.getAll()?.each{ v ->
        def a = v.article

        def article         = [id:a.id, name:a.name, mbcode:a.mbcode, pbcode:a.pbcode, details:a.details]
        def price           = [id: v.id, m01i006001:article, price:v.price, date:v.date]
        prices << price
    }
    return prices
}

但是当我打电话给这家商店时,客户端加载问题。我不能偷懒它的父母。它的节目总是渴望的。

如果您有任何解决此错误的想法,请告诉我。

提前致谢

4

1 回答 1

1

这不是解决方案。我为此创建了一个代理模型,我删除了所有不必要的关系然后我解决了我的问题,这意味着我只保留一个属于所以只保留一个关联键。

于 2013-04-02T08:59:58.583 回答