SQL下的GORM准则将是什么
订单表:
客户表:
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column. Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables:strong text
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
Sql将使用那些列产生那些数据
GORM模型:
class Order{
Long orderId
Long customerId
def orderDate
}
class Customer{
Long customerID
Long customerName
def contactName
def country
}
最佳答案
我正在做出一些猜测,以创建一个与您在那里描述的持久性模型相匹配的对象模型。
class Customer {
String customerName
String contactName
String country
static mapping = {
table 'Customers'
version false
id column: 'CustomerID'
customerName column: 'CustomerName'
contactName column: 'ContactName'
country column: 'Country'
}
}
class Order {
Customer customer
Date orderDate
static mapping = {
table 'Orders'
version false
id column: 'OrderID'
customer column: 'CustomerID'
orderDate column: 'OrderDate'
}
}
执行如下查询:
Order.findAll {
createAlias 'customer', 'cust'
projections {
property 'id'
property 'orderDate'
property 'cust.customerName'
}
}
这将导致如下所示的SQL:
select this_.OrderID as y0_, this_.OrderDate as y1_, cust1_.CustomerName as y2_ from Orders this_ inner join Customers cust1_ on this_.CustomerID=cust1_.CustomerID
关于sql - SQL下面的GORM(grails)条件是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61114242/