-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Has Many Join on nullable value #950
Comments
Oh wow, the timing is good. Exact same issue for me. type Individual struct {
bun.BaseModel `bun:"individuals,alias:ind"`
ID string `json:"ID" required:"true" bun:",pk"`
WorkspaceID string `json:"WorkspaceID" required:"true"`
HubspotObjects []*HubspotObject `json:"HubspotObjects" bun:"rel:has-many,join:id=individual_id"`
}
type HubspotObject struct {
bun.BaseModel `bun:"hubspot_objects,alias:hso"`
ID string `json:"ID" required:"true" bun:",pk"`
WorkspaceID string `json:"WorkspaceID" required:"true"`
IndividualID *string `json:"IndividualID"` // can be null
OrganizationID *string `json:"OrganizationID"` // can be null
SyncedAt *time.Time `json:"SyncedAt"`
UpdatedAt time.Time `json:"UpdatedAt" required:"true"`
CreatedAt time.Time `json:"CreatedAt" required:"true"`
}
func (h *Handlers) SearchIndividuals() {
ids := []string{"a", "z"}
// load the individuals
individuals := []entity.Individual{}
if err := h.bun.NewSelect().
Model(&individuals).
Relation("HubspotObjects").
Where("ind.id IN (?)", bun.In(ids)).
Scan(ctx); err != nil {
return nil, apperrors.SqlError(err, "search individuals")
}
} And it errors: |
I am also having this problem with a custom type for my pk field, so |
Using pointers with key fields in a has-many join fails. This fixes that.
@JunNishimura not sure who's reviewing PRs these days, but I pushed a fix for this, really need to get it merged asap. It's causing my company a lot of pain trying to migrate to bun. |
I reverted to just doing a manual join on the table, I've only used it to fetch the base record when I need to do where clauses it might work for the nested records as well. |
@comsma that defeats the purpose of an ORM. My PR fixes the issue if you want to maintain your own fork until this gets merged. |
@JunNishimura PR is here. |
@jeffreydwalter However, I will check to make sure that the PR you submitted is acceptable so that it can be approved ASAP. |
fix: fix issue with has-many join and pointer fields (uptrace#950)
any news ? |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed. |
Future reference, this was fixed with #983 |
I am trying to join a list of transactions(InvTran) to InventoryReceiptsLine. Being that InvTran.SubDocumentNo is sql.NullFloat64 i get an error saying
*errors.errorString: bun: has-many relation=Ira does not have base model=InventoryReceiptsLine with id=[{%!q(float64=5.17761e+06) %!q(bool=true)} '華'] (check join conditions)
.How can i join these without changing the type of SubDocumentNo as these models are base on a active erp system in which i do not have control over the schema?
The text was updated successfully, but these errors were encountered: