Skip to content

Commit

Permalink
[hooks] fix belongs to
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Mar 19, 2017
1 parent 1d11b58 commit 4e04531
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
22 changes: 9 additions & 13 deletions hooks/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func CreateExec(b *Book, e *engine.Engine) error {
//AfterCreate executes hooks after Creating records
func AfterCreate(b *Book, e *engine.Engine) error {
if dialects.IsQL(e.Dialect) {
return QLAfterCreate(b, e)
QLAfterCreate(b, e)
}
s, ok := b.Update.Get(model.HookSaveAfterAss)
if !ok {
Expand Down Expand Up @@ -345,15 +345,7 @@ func QLAfterCreate(b *Book, e *engine.Engine) error {
if !ok {
return errors.New("missing update exec hook")
}
err = exec.Exec(b, ne)
if err != nil {
return err
}
s, ok := b.Update.Get(model.HookSaveAfterAss)
if !ok {
return fmt.Errorf("missing hook %s", model.HookSaveAfterAss)
}
return s.Exec(b, ne)
return exec.Exec(b, ne)
}

func fixWhere(s *model.Scope) error {
Expand Down Expand Up @@ -501,6 +493,9 @@ func SaveBeforeAssociation(b *Book, e *engine.Engine) error {
if err != nil {
return err
}
if dialects.IsQL(e.Dialect) {
QLAfterCreate(b, ne)
}
if len(relationship.ForeignFieldNames) != 0 {
// set value's foreign key
for idx, fieldName := range relationship.ForeignFieldNames {
Expand Down Expand Up @@ -534,7 +529,6 @@ func SaveAfterAssociation(b *Book, e *engine.Engine) error {
if ok, rel := scope.SaveFieldAsAssociation(e, field); ok {
switch rel.Kind {
case "has_many":
// pretty.Println(rel)
fv := field.Field.Addr()
if fv.Kind() == reflect.Ptr {
fv = fv.Elem()
Expand All @@ -543,7 +537,6 @@ func SaveAfterAssociation(b *Book, e *engine.Engine) error {
fieldValue := field.Field.Addr().Interface()
ne := cloneEngine(e)
ne.Scope.Value = fieldValue
// pretty.Println(rel)
if len(rel.ForeignFieldNames) != 0 {
// set value's foreign key
for idx, fieldName := range rel.ForeignFieldNames {
Expand Down Expand Up @@ -998,7 +991,10 @@ func PreloadBelogsTo(b *Book, e *engine.Engine, field *model.Field, conditions [
if err != nil {
return err
}

if dialects.IsQL(pdb.Dialect) {
fmt.Println(pdb.Scope.SQL)
fmt.Println(pdb.Scope.SQLVars)
}
// assign find results
rVal := reflect.ValueOf(results)
if rVal.Kind() == reflect.Ptr {
Expand Down
3 changes: 0 additions & 3 deletions ngorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,6 @@ func testDB_Preload(t *testing.T, db *DB) {
&fixture.CreditCard{},
&fixture.Address{},
)
if isQL(db) {
t.Skip()
}
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 4e04531

Please sign in to comment.