Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objectbox-go generator can not handle a struct with multiple lazy loaded relations #45

Open
sgbell opened this issue Jun 4, 2022 · 0 comments

Comments

@sgbell
Copy link

sgbell commented Jun 4, 2022

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.

Modules involved:
github.com/objectbox/objectbox-generator v0.13.0
github.com/objectbox/objectbox-go v1.6.1

Golang version:
go version go1.17.9 linux/amd64

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-gogen
type Token struct {
Id uint64
Token string
ExpiryDate uint64 objectbox:"date"
}

type Track struct {
Id uint64
path string objectbox:"index:hash64"
artistName string objectbox:"index:hash64"
songName string objectbox:"index:hash64"
albumName string objectbox:"index:hash64"
albumTrackNumber int
}

type Playlist struct {
Id uint64
CurrentTrackId uint16
Elapsed int
Tracks []*Track
}

type Friend struct {
Id uint64
friendId uint64
}
type User struct {
Id uint64 // going to be an internal objectBoxId
FirstName string
LastName string
EmailAddress string objectbox:"index:hash64"
Password string
Enabled bool
Tokens []*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

nick-dijkshoorn added a commit to nick-dijkshoorn/objectbox-generator that referenced this issue Aug 24, 2023
…a struct with multiple lazy loaded relations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant