Skip to content

Conversation

erizocosmico
Copy link
Contributor

If you have N relationships, only the last one was taken into account. GGWP.

@codecov
Copy link

codecov bot commented Jun 13, 2017

Codecov Report

Merging #174 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #174   +/-   ##
=======================================
  Coverage   81.23%   81.23%           
=======================================
  Files          16       16           
  Lines        3443     3443           
=======================================
  Hits         2797     2797           
  Misses        439      439           
  Partials      207      207

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb22fc2...a6052fa. Read the comment docs.

@nadiamoe
Copy link
Contributor

nadiamoe commented Jun 13, 2017

May I note that the current release (without this patch) does not update in-memory ID fields of models inserted within one-level of recursion when the relationsip is not a slice of pointers.

This is, if A has many Bs, after doing astore.Save(&a), a.bs[i].ID is still 0. I'm not sure if this patch fixes that behaviour too.

@nadiamoe
Copy link
Contributor

nadiamoe commented Jun 13, 2017

Also, (I apologize for the doublepost), and this is a little weird, if we have the following scenario:

type A struct {
    kallax.Model
    ID int64 `pk:"autoincr"`

    Bs []*B // Note the pointer
}


type B struct {
    kallax.Model
    ID int64 `pk:"autoincr"`

    Cs []C // Note this is not a pointer
}


type C struct {
    kallax.Model
    ID int64 `pk:"autoincr"`
}

Doing

astore.Save(&a) // This works, inserts a and its Bs, and sets `a.bs[i].ID` in memory
// for each a.bs
bstore.Save(&a.bs[i]) // cs are NOT saved

Does NOT trigger the insertion of any C, despite a.bs[i].ID being correctly set.

If I change B to


type B struct {
    kallax.Model
    ID int64 `pk:"autoincr"`

    Cs []*C // Note this now a pointer
}

Then it works as it should.

@erizocosmico erizocosmico force-pushed the fix/insert-noptr-slice branch from 137be89 to 53b4e95 Compare June 13, 2017 13:07
@erizocosmico erizocosmico force-pushed the fix/insert-noptr-slice branch from 53b4e95 to a6052fa Compare June 13, 2017 13:09
@erizocosmico
Copy link
Contributor Author

Ok, everything should be fixed now. I'm merging this and releasing. If it's not, please raise an issue.

@erizocosmico erizocosmico merged commit b00aebb into src-d:master Jun 13, 2017
@erizocosmico erizocosmico deleted the fix/insert-noptr-slice branch June 13, 2017 13:09
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

Successfully merging this pull request may close these issues.

2 participants