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

invalid recursive type when using has_many and belongs_to #59

Closed
u007 opened this issue Apr 13, 2018 · 5 comments
Closed

invalid recursive type when using has_many and belongs_to #59

u007 opened this issue Apr 13, 2018 · 5 comments

Comments

@u007
Copy link
Member

u007 commented Apr 13, 2018

example:

class Paper {
  Code Code `json:"code" has_many:"codes"`
}

class Code {
  PaperID uuid `json:"paper_id" db:"paper_id"`
  Paper Paper `json:"paper" belongs_to:"paper"`//if i remove this line, the error wont occur
}

throwing error compilation
invalid recursive type Paper

i suspect its due to PaperID

@u007
Copy link
Member Author

u007 commented Apr 13, 2018

btw, is there any reason not to use gorm?
i think their belongs to and has many is more complete

but i like the way fizz migration works

@stanislas-m
Copy link
Member

@u007 In Go, you can't define structs with circular references. You'll need to use a pointer attribute instead.

@u007
Copy link
Member Author

u007 commented Apr 16, 2018

did u mean adding pointer to code.Paper ?

class Code {
  PaperID uuid `json:"paper_id" db:"paper_id"`
  Paper *Paper `json:"paper" belongs_to:"paper"`//if i remove this line, the error wont occur
}

@stanislas-m
Copy link
Member

Yup, it should work for the Go part. Not sure it's allowed with the Pop side, though.

@stanislas-m
Copy link
Member

I confirm it works with the pointer.

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

2 participants