a8m / a8m/rql

Circular Struct Fields goes into infinite loop

オープン
#53 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
367
フォーク
43
PR マージ指標
30日以内にマージされた PR はありません

説明

If the struct model used refers to any field with same type as that of model directly or indirectly in downstream dependencies then parser creation goes into infinite loop and program never proceeds. Example of such model. ( here Manager is of type User )
`type User struct {
ID uint ```gorm:"primary_key" rql:"filter,sort"\```
ManagerId *uint
Manager *User
DirectReports []User ```gorm:"foreignKey:ManagerId"\```
Admin bool ```rql:"filter"```
Name string ```rql:"filter"```
Tags datatypes.JSONSlice[string] ```rql:"filter"```
AddressName string ```rql:"filter"```
CreatedAt time.Time ```rql:"filter,sort"```
}`
I propose here two possible solutions
1. We introduce a `nested` tag like filter and sort and if a field of type struct is marked nested then only process it. This breaks the convention yet i have already forked this repo and wrote a code which works with this.
2. Generate all things parser does at run time ( on the fly while parsing queries and not while creating parser) and don't even preprocess model with parser and in doing so we can break loop till all fields refered in query are are parsed.

Would be happy to discuss both the approaches ( or if there could be any other ) and create necessary PR to fix this.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。