add additional test
This commit is contained in:
parent
68dbbabb99
commit
31cddca786
3 changed files with 96 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
|
|
@ -776,6 +777,98 @@ ORDER BY city.city_id, address.address_id, customer.customer_id;
|
|||
`)
|
||||
}
|
||||
|
||||
// Test join with custom primary keys (null.Int)
|
||||
func TestExecutionCustomPKTypes2(t *testing.T) {
|
||||
|
||||
var dest []struct {
|
||||
CityID null.Int `sql:"primary_key" alias:"city.city_id"`
|
||||
CityName string `alias:"city.city"`
|
||||
|
||||
Customers []struct {
|
||||
CustomerID null.Int `sql:"primary_key" alias:"customer_id"`
|
||||
LastName *string `alias:"last_name"`
|
||||
|
||||
Address struct {
|
||||
AddressID null.Int `sql:"primary_key" alias:"AddressId"`
|
||||
AddressLine string `alias:"address.address"`
|
||||
} `alias:"address.*"`
|
||||
} `alias:"customer"`
|
||||
}
|
||||
|
||||
stmt := City.
|
||||
INNER_JOIN(Address, Address.CityID.EQ(City.CityID)).
|
||||
INNER_JOIN(Customer, Customer.AddressID.EQ(Address.AddressID)).
|
||||
SELECT(
|
||||
City.CityID,
|
||||
City.City,
|
||||
Customer.CustomerID,
|
||||
Customer.LastName,
|
||||
Address.AddressID,
|
||||
Address.Address,
|
||||
).
|
||||
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
|
||||
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
|
||||
|
||||
testutils.AssertDebugStatementSql(t, stmt, `
|
||||
SELECT city.city_id AS "city.city_id",
|
||||
city.city AS "city.city",
|
||||
customer.customer_id AS "customer.customer_id",
|
||||
customer.last_name AS "customer.last_name",
|
||||
address.address_id AS "address.address_id",
|
||||
address.address AS "address.address"
|
||||
FROM dvds.city
|
||||
INNER JOIN dvds.address ON (address.city_id = city.city_id)
|
||||
INNER JOIN dvds.customer ON (customer.address_id = address.address_id)
|
||||
WHERE (city.city = 'London'::text) OR (city.city = 'York'::text)
|
||||
ORDER BY city.city_id, address.address_id, customer.customer_id;
|
||||
`, "London", "York")
|
||||
|
||||
err := stmt.Query(db, &dest)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(dest), 2)
|
||||
testutils.AssertJSON(t, dest, `
|
||||
[
|
||||
{
|
||||
"CityID": 312,
|
||||
"CityName": "London",
|
||||
"Customers": [
|
||||
{
|
||||
"CustomerID": 252,
|
||||
"LastName": "Hoffman",
|
||||
"Address": {
|
||||
"AddressID": 256,
|
||||
"AddressLine": "1497 Yuzhou Drive"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CustomerID": 512,
|
||||
"LastName": "Vines",
|
||||
"Address": {
|
||||
"AddressID": 517,
|
||||
"AddressLine": "548 Uruapan Street"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"CityID": 589,
|
||||
"CityName": "York",
|
||||
"Customers": [
|
||||
{
|
||||
"CustomerID": 497,
|
||||
"LastName": "Sledge",
|
||||
"Address": {
|
||||
"AddressID": 502,
|
||||
"AddressLine": "1515 Korla Way"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
`)
|
||||
}
|
||||
|
||||
func TestJoinQuerySliceWithPtrs(t *testing.T) {
|
||||
type FilmsPerLanguage struct {
|
||||
Language model.Language
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue