Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Multiple extends of the same type #1270

Closed
mskrip opened this issue Apr 12, 2019 · 1 comment · Fixed by #1284
Closed

Multiple extends of the same type #1270

mskrip opened this issue Apr 12, 2019 · 1 comment · Fixed by #1284
Labels

Comments

@mskrip
Copy link
Contributor

mskrip commented Apr 12, 2019

While having two extends fields with the same type it is not possible to bind the values into them correctly if the query only queries some of the fields.

Meaning query SELECT sc.Width, sc.Height FROM Books AS b LEFT JOIN Size AS s ON s.ID = b.SizeClosed with following data structure binds the data into SizeOpen instead of SizeClosed for me.

type Size struct {
	Width  *float64 `json:"width" xorm:"'Width'"`
	Height *float64 `json:"height" xorm:"'Height'"`
}

type Book struct {
        SizeOpen   Size `json:"size_open" xorm:"extends"`
        SizeClosed Size `json:"size_closed" xorm:"extends"`
}

Would it for example be possible to set something like a prefix with extends tag? This prefix would then have to be on the query on all the child columns. So something like SELECT sc.Width AS ClosedWidth, sc.Height AS ClosedHeight FROM Books AS b LEFT JOIN Size AS s ON s.ID = b.SizeClosed with following tags would be able to bind it correctly.

type Book struct {
        SizeOpen   Size `json:"size_open" xorm:"extends 'Open'"`
        SizeClosed Size `json:"size_closed" xorm:"extends 'Closed'"`
}
@lunny lunny added the proposal label Apr 12, 2019
@lunny
Copy link
Member

lunny commented Apr 12, 2019

It seems that's a good idea. Or we can use extends('Open')

lunny pushed a commit that referenced this issue Jun 23, 2019
Added new syntax like `extends('Prefix')` to enable matching all
extended fields as 'PrefixFieldName'.

Close #1270
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants