You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
objectbox-go generator can not handle a struct with multiple lazy loaded relations #45
Hi Guys,
Just messing around with objectbox-go for use as data storage for my app, and I came across the idea
of lazy loading related objects. I found that If I create a struct with more than 1 lazy loaded relation,
the generator breaks badly, to the point that if I remove all but 1 of the lazy defines on a relation, it works fine.
As I'm new to golang, I don't think I'm in the right headspace yet to fix it myself, but that being said, I can
point you in the direction I think needs the fix...
internal/generator/go/templates/binding.go
seems to be the first part to have issues, as with multiple lazy loaded relations, the templated code at line
165 misses a new line in the template, and causes errors in the code.
But then it totally dies somewhere in the templated code after line 193.
Granted those line numbers are from looking at the current source of the repo.
Below is my model.go file for the generator to have fun with.
package model
//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogentypeTokenstruct {
Iduint64TokenstringExpiryDateuint64`objectbox:"date"`
}
typeTrackstruct {
Iduint64pathstring`objectbox:"index:hash64"`artistNamestring`objectbox:"index:hash64"`songNamestring`objectbox:"index:hash64"`albumNamestring`objectbox:"index:hash64"`albumTrackNumberint
}
typePlayliststruct {
Iduint64CurrentTrackIduint16ElapsedintTracks []*Track
}
typeFriendstruct {
Iduint64friendIduint64
}
typeUserstruct {
Iduint64// going to be an internal objectBoxIdFirstNamestringLastNamestringEmailAddressstring`objectbox:"index:hash64"`PasswordstringEnabledboolTokens []*Token`objectbox:"lazy"`Tracks []*Track`objectbox:"lazy"`Playlists []*Playlist`objectbox:"lazy"`SharedPlaylists []*Playlist`objectbox:"lazy"`Friends []*Friend`objectbox:"lazy"`
}
output of command: go generate ./...
Generating ObjectBox bindings for model.go
failed to format generated binding file model.obx.go: 1632:8: expected ';', found 'if' (and 3 more errors)
exit status 2
internal/model/model.go:3: running "go": exit status 1
@doffi88 Thanks for reporting! The Relations documentation suggests that lazy loading is not the default. As a workaround, maybe try to remove the lazy annotation and use eagerly loaded relations.
Activity
Bugfix for issue objectbox#45: objectbox-go generator can not handle …
doffi88 commentedon Mar 27, 2025
Team, this bug is still present. I'm also experiencing the issue. Why hasn't the fix been merged?
greenrobot-team commentedon Apr 1, 2025
@doffi88 Thanks for reporting! The Relations documentation suggests that lazy loading is not the default. As a workaround, maybe try to remove the lazy annotation and use eagerly loaded relations.