mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: add support for referencing fks to existing fields (#1289)
This commit is contained in:
@@ -357,7 +357,8 @@ func (cq *CarQuery) sqlAll(ctx context.Context) ([]*Car, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Car)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_car; fk != nil {
|
||||
fk := nodes[i].user_car
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -24,9 +24,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{CarsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cars_users_car",
|
||||
Columns: []*schema.Column{CarsColumns[1]},
|
||||
|
||||
Symbol: "cars_users_car",
|
||||
Columns: []*schema.Column{CarsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -86,16 +85,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "users_users_children",
|
||||
Columns: []*schema.Column{UsersColumns[10]},
|
||||
|
||||
Symbol: "users_users_children",
|
||||
Columns: []*schema.Column{UsersColumns[10]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "users_users_spouse",
|
||||
Columns: []*schema.Column{UsersColumns[11]},
|
||||
|
||||
Symbol: "users_users_spouse",
|
||||
Columns: []*schema.Column{UsersColumns[11]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
|
||||
@@ -490,7 +490,8 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_children; fk != nil {
|
||||
fk := nodes[i].user_children
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
@@ -544,7 +545,8 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_spouse; fk != nil {
|
||||
fk := nodes[i].user_spouse
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -357,7 +357,8 @@ func (cq *CarQuery) sqlAll(ctx context.Context) ([]*Car, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Car)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_car; fk != nil {
|
||||
fk := nodes[i].user_car
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -24,9 +24,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{CarsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cars_users_car",
|
||||
Columns: []*schema.Column{CarsColumns[1]},
|
||||
|
||||
Symbol: "cars_users_car",
|
||||
Columns: []*schema.Column{CarsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -107,9 +106,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{PetsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "pets_users_pets",
|
||||
Columns: []*schema.Column{PetsColumns[1]},
|
||||
|
||||
Symbol: "pets_users_pets",
|
||||
Columns: []*schema.Column{PetsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -158,16 +156,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{FriendsColumns[0], FriendsColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "friends_user",
|
||||
Columns: []*schema.Column{FriendsColumns[0]},
|
||||
|
||||
Symbol: "friends_user",
|
||||
Columns: []*schema.Column{FriendsColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "friends_friend",
|
||||
Columns: []*schema.Column{FriendsColumns[1]},
|
||||
|
||||
Symbol: "friends_friend",
|
||||
Columns: []*schema.Column{FriendsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
|
||||
@@ -357,7 +357,8 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Pet)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].owner_id; fk != nil {
|
||||
fk := nodes[i].owner_id
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user