[英]Grails GORM double nested association query
我有以下域類(具有相關屬性):
class Order {
static belongsTo = [ restaurant : Restaurant ]
}
class Restaurant {
static belongsTo = [ country : Country ]
}
class Country {
}
表結構很好,數據生成正確。 但是當我試圖獲得其餐館屬於特定國家的所有訂單的清單時 ,我只獲得一個訂單。
這是一個測試無法證明:
def testOrdersByCountry(){
given:
def c = new Country().save()
def r = new Restaurant(country:c).save()
new Order(restaurant:r).save()
new Order(restaurant:r).save()
new Order(restaurant:r).save()
when:
def orders = Order.withCriteria {
restaurant {
country {
eq 'id', c.id
}
}
}
then:
orders.size() == 3
}
你需要很多
static hasMany = [orders : Order]
在課堂Restaurant
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.