forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pocketbase#1689] fixed cascade delete condition on rel records with …
…the same id as the main record
- Loading branch information
1 parent
a74d227
commit eb1246f
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ func (dao *Dao) FindRecordsByIds( | |
// Returns an empty slice if no records are found. | ||
// | ||
// Example: | ||
// | ||
// expr1 := dbx.HashExp{"email": "[email protected]"} | ||
// expr2 := dbx.NewExp("LOWER(username) = {:username}", dbx.Params{"username": "test"}) | ||
// dao.FindRecordsByExpr("example", expr1, expr2) | ||
|
@@ -402,13 +403,16 @@ func (dao *Dao) cascadeRecordDelete(mainRecord *models.Record, refs map[*models. | |
// @todo optimize single relation lookup in v0.12+ | ||
query := dao.RecordQuery(refCollection). | ||
Distinct(true). | ||
AndWhere(dbx.Not(dbx.HashExp{recordTableName + ".id": mainRecord.Id})). | ||
InnerJoin(fmt.Sprintf( | ||
// note: the case is used to normalize the value access | ||
`json_each(CASE WHEN json_valid([[%s]]) THEN [[%s]] ELSE json_array([[%s]]) END) as {{%s}}`, | ||
prefixedFieldName, prefixedFieldName, prefixedFieldName, uniqueJsonEachAlias, | ||
), dbx.HashExp{uniqueJsonEachAlias + ".value": mainRecord.Id}) | ||
|
||
if refCollection.Id == mainRecord.Collection().Id { | ||
query.AndWhere(dbx.Not(dbx.HashExp{recordTableName + ".id": mainRecord.Id})) | ||
} | ||
|
||
// trigger cascade for each batchSize rel items until there is none | ||
batchSize := 4000 | ||
rows := make([]dbx.NullStringMap, 0, batchSize) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters