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

Preload Breaking in 0.21 #215

Closed
ddanurwenda opened this issue Sep 27, 2021 · 2 comments
Closed

Preload Breaking in 0.21 #215

ddanurwenda opened this issue Sep 27, 2021 · 2 comments

Comments

@ddanurwenda
Copy link

Hi, I was trying to upgrade from 0.10 to latest but found an issue introduced in 0.21.

Using prior version we can do the following

type Discussion struct {
	ID          int                  
	ComplaintID *int                 
	Complaint   *DiscussionComplaint `autosave:"true"`
}

// discussion has zero or one complaint
type DiscussionComplaint struct {
	ID         int
}

// Table to override table name
func (dc DiscussionComplaint) Table() string {
	return "complaints"
}

func main() {
	var discussions []Discussion
	// on 0.20 we can do the following
	complaintFilter := rel.Gte("complaint_id", start).And(rel.Lte("complaint_id", finish))
	pg.FindAll(context.Background(), &discussions, rel.Preload("complaint"), complaintFilter)
	for _, discussion := range discussions {
		fmt.Println("discussion id", discussion.ID)
		fmt.Println("discussion.complaint_id", discussion.ComplaintID)
		fmt.Println("discussion.complaint.id", discussion.Complaint.ID)
	}
}

starting from 0.21 it will raise an error
panic: value method main.DiscussionComplaint.Table called using nil *DiscussionComplaint pointer.

Do we need to add some kind of adjustment to be able to upgrade to 0.21? Thanks

@Fs02
Copy link
Member

Fs02 commented Sep 27, 2021

Looks like related to this: #198

Your code should works if DiscussionComplaint doesn't define a custom table name, let me fix this
Thanks for reporting

@Fs02
Copy link
Member

Fs02 commented Sep 27, 2021

Fix is released in v0.25.0, let me know if this fixed the issue
https://github.com/go-rel/rel/releases/tag/v0.25.0

@Fs02 Fs02 closed this as completed Oct 1, 2021
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