Join与软删除结合使用的问题 #2082

Open
opened 2021-12-15 12:18:24 +00:00 by wave · 0 comments

编写如下数据结构:

type A struct {
	Id int64
	BId int64
	DeletedAt     time.Time `xorm:"deleted"`
}

type B struct {
	Id int64
	DeletedAt     time.Time `xorm:"deleted"`
}

type AB struct {
	B `xorm:"extends"`
	A `xorm:"extends"`
}

其中,在A表里有两条数据,一条已删除,一条未删除
采用如下代码:

orm.Table("b").Join("inner","a", "a.b_id = b.id").Find(&ab)

生成对应命令:

SELECT * FROM `b` inner JOIN `a` ON a.b_id = b.id WHERE (`b`.`deleted_at`='' OR `b`.`deleted_at` IS NULL)

可以看到a中已经软删除的数据也会被查出,请问有什么方法规避吗?

编写如下数据结构: ``` type A struct { Id int64 BId int64 DeletedAt time.Time `xorm:"deleted"` } type B struct { Id int64 DeletedAt time.Time `xorm:"deleted"` } type AB struct { B `xorm:"extends"` A `xorm:"extends"` } ``` 其中,在A表里有两条数据,一条已删除,一条未删除 采用如下代码: ``` orm.Table("b").Join("inner","a", "a.b_id = b.id").Find(&ab) ``` 生成对应命令: ``` SELECT * FROM `b` inner JOIN `a` ON a.b_id = b.id WHERE (`b`.`deleted_at`='' OR `b`.`deleted_at` IS NULL) ``` 可以看到a中已经软删除的数据也会被查出,请问有什么方法规避吗?
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#2082
No description provided.