forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
471 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
package pop | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/markbates/inflect" | ||
) | ||
import "fmt" | ||
|
||
func (c *Connection) BelongsTo(model interface{}) *Query { | ||
return Q(c).BelongsTo(model) | ||
} | ||
|
||
func (q *Query) BelongsTo(model interface{}) *Query { | ||
m := &Model{Value: model} | ||
tn := m.TableName() | ||
tn = inflect.Singularize(tn) | ||
args := []interface{}{m.ID()} | ||
q.WhereClauses = append(q.WhereClauses, Clause{fmt.Sprintf("%s_id = ?", tn), args}) | ||
q.Where(fmt.Sprintf("%s = ?", m.AssociationName()), m.ID()) | ||
return q | ||
} | ||
|
||
func (c *Connection) BelongsToThrough(bt, thru interface{}) *Query { | ||
return Q(c).BelongsToThrough(bt, thru) | ||
} | ||
|
||
func (q *Query) BelongsToThrough(bt, thru interface{}) *Query { | ||
q.BelongsToThroughClauses = append(q.BelongsToThroughClauses, BelongsToThroughClause{ | ||
BelongsTo: &Model{Value: bt}, | ||
Through: &Model{Value: thru}, | ||
}) | ||
return q | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package columns | ||
|
||
import "fmt" | ||
|
||
type Column struct { | ||
Name string | ||
Writeable bool | ||
Readable bool | ||
SelectSQL string | ||
} | ||
|
||
func (c Column) UpdateString() string { | ||
return fmt.Sprintf("%s = :%s", c.Name, c.Name) | ||
} | ||
|
||
func (c *Column) SetSelectSQL(s string) { | ||
c.SelectSQL = s | ||
c.Writeable = false | ||
c.Readable = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package columns_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/markbates/pop/columns" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Column_UpdateString(t *testing.T) { | ||
r := require.New(t) | ||
c := columns.Column{Name: "foo"} | ||
r.Equal(c.UpdateString(), "foo = :foo") | ||
} |
Oops, something went wrong.