Commit Graph

2426 Commits

Author SHA1 Message Date
Baiju Muthukadan bd513dd580 test case for single parameter for Open 2016-10-08 21:52:15 +05:30
Jinzhu 39165d4980 Refactor named value support for PolymorphicType 2016-10-07 22:19:28 +08:00
Baiju Muthukadan 0d54677e13 if no arguments, return error at once 2016-10-07 17:12:29 +05:30
Jinzhu ab703afe97 Merge pull request #1199 from jugglinmike/empty-associations
Return empty slice for associations with 0 results
2016-10-06 21:23:04 +08:00
Jinzhu 33abb2e9e0 Merge branch 'slockij-named-polymorphic-relation' 2016-10-06 20:34:26 +08:00
Jinzhu afaadc3942 Refactor named value support for PolymorphicType 2016-10-06 20:33:48 +08:00
slockij 1413e55339 Add named value for PolymorphicType (to replace scope.TableName) 2016-09-28 22:44:43 +02:00
Mike Pennisi f06d6412de Return empty slice for associations with 0 results
When using `Preload` to include the results of a "has many"
relationship, Gorm previously returned an uninitialized slice for any
such relations that bore zero records. This distinction was most
apparent when the results were marshalled to a JSON representation--a
record with zero related records would be represented with `null`.

For example, consider the following schema:

    id | name
    ---|------
    1  | Lorin
    2  | Sue

    id | p_id | value
    ---|------|-------------------
    1  | 1    | lorin@example.com
    2  | 1    | lorin2@example.com

Querying with:

    db.Preload("Email").Find(&people)

And marshalling the resulting value of `people` to JSON would yield the
following string:

    [
      {
        "name": "Lorin",
        "email": [
          "lorin@example.com",
          "lorin2@example.com"
        ]
      },
      {
        "name": "Sue",
        "email": null
      }
    ]

Beyond being inconsistent, the value `null` in this response differs
semantically from the actual state of the database. The database
actually has zero related records for the second user, so a JSON value
of `[]` is appropriate.

Update the callback that processes "has many" relationships to
communicate empty query results with an empty slice.
2016-09-27 17:09:57 -04:00
Jinzhu 5ec2f6ceb6 Merge pull request #1190 from cloudaice/master
fix goroutine leak while calling db.Ping() error
2016-09-25 14:26:37 +08:00
Jinzhu 129a142371 Merge pull request #1192 from danhardman/patch-1
Update CONTRIBUTING.md executable script template
2016-09-25 14:24:25 +08:00
Dan Hardman 79a91d7548 Update CONTRIBUTING.md executable script template
Change `db` to type `*gorm.DB` to reflect latest version of gorm.
Remove re-declarations of `db, err`
2016-09-20 16:55:01 +01:00
cloudaice 7dcd80ddf9 fix goroutine leak while calling db.Ping() error 2016-09-18 14:26:16 +08:00
Jinzhu 041cd3dd31 Fix scan ignored fields, close #1117 2016-09-13 09:29:36 +08:00
Jinzhu 3425c1d38d Set PrimaryField IsBlank to false after read from returning value 2016-09-13 08:24:29 +08:00
Jinzhu 6732a50dfb Get Dialect of DB 2016-09-13 07:41:42 +08:00
Jinzhu 02f6ae3c4e If failed to update current record with Save, try to create a new one 2016-09-07 21:54:19 +08:00
Jinzhu 446ce99a42 Support set prefix for embedded struct 2016-09-05 22:26:57 +08:00
Jinzhu f26fa242cc Support specify GORM tag setting inside scanner 2016-08-25 17:59:26 +08:00
Jinzhu 35a2a004d8 Strict select argument check for Count 2016-08-15 21:28:07 +08:00
Jinzhu 2f27f0f27f Fix TestUpdateDecodeVirtualAttributes 2016-08-14 16:13:50 +08:00
elgris fb09befb9b Adds processing of ignored fields on Update 2016-08-14 16:12:57 +08:00
Jinzhu 34e75afb42 Support specify count select argument 2016-08-14 15:15:09 +08:00
Jinzhu 8f0f5df8c6 Don't set auto increment primary key's HasDefaultValue to true 2016-08-13 21:46:49 +08:00
Jinzhu 294eb58fc2 Merge branch 'GhostRussia-fix_join_with_same_fields' 2016-08-13 21:23:25 +08:00
Jinzhu fde205f758 Refactor joining multiple tables with the same fields 2016-08-13 21:23:18 +08:00
zardak ccb35db934 Fix failing sqlite3 tests due to db connection not being closed 2016-08-13 21:05:24 +08:00
Nick Sarbicki 084968cc0a Fixing go get error
Get this on install:

    ../../jinzhu/gorm/utils.go:137: syntax error: unexpected range, expecting {
    ../../jinzhu/gorm/utils.go:147: non-declaration statement outside function body
    ../../jinzhu/gorm/utils.go:148: syntax error: unexpected }
2016-08-13 21:05:24 +08:00
Jinzhu 9cdda4e8ee Expose current database name API 2016-08-13 21:05:24 +08:00
Jinzhu dda88dd08c Merge pull request #1140 from zardak/fix-tests
Fix failing sqlite3 tests due to db connection not being closed
2016-08-11 10:59:00 +08:00
Vladislav Fursov e8c14bd1b3 Fixed a bug when joining multiple tables with the same fields and where on the same field. 2016-08-09 14:28:43 +09:00
zardak bcff1df589 Fix failing sqlite3 tests due to db connection not being closed 2016-08-07 13:00:06 +03:00
Jinzhu a646b13548 Merge pull request #1119 from NDevox/master
Fixes #1118
2016-07-20 08:36:53 +09:00
Nick Sarbicki d7fa7d0859 Fixing go get error
Get this on install:

    ../../jinzhu/gorm/utils.go:137: syntax error: unexpected range, expecting {
    ../../jinzhu/gorm/utils.go:147: non-declaration statement outside function body
    ../../jinzhu/gorm/utils.go:148: syntax error: unexpected }
2016-07-16 14:14:46 +01:00
Jinzhu b507cdf93d Expose current database name API 2016-07-11 21:37:44 +08:00
Jinzhu 613c065569 Merge branch 'RichardKnop-feature/fix-preload-duplicates' 2016-07-10 21:34:49 +08:00
Jinzhu ca46038cb4 Fix preload duplicates has many related objects 2016-07-10 21:34:37 +08:00
Richard Knop 24501a3c1a Fixed bug when preload duplicates has many related objects. 2016-07-09 18:51:38 +08:00
Jinzhu 3324ab2063 Merge pull request #1075 from cdevienne/fix_autoincrement
Fix autoincrement
2016-07-05 06:36:50 +08:00
Jinzhu c1c4f9f86e Add ORDER BY sql expression support 2016-06-28 11:15:42 +08:00
Jinzhu 321d10b67b Fix broken tests for postgres 2016-06-24 07:48:03 +08:00
Jay Taylor 1485f4bce9 Use validated interface{} for limit/offset values to ensure values greater than
max 32-bit integer are addressable, and in a backwards-compatible way.
2016-06-23 06:29:51 -07:00
Christophe de Vienne 328fe672c8 Test AUTO_INCREMENT only on postgres
Only the postgres dialect handles AUTO_INCREMENT on non-primary key.
So we skip the auto increment test for other dialects.

The mysql case is a little trickier because the simple presence of the
'AUTH_INCREMENT' tag produces a faulty 'CREATE TABLE' statement. Hence
we need to remove it when present.
2016-06-20 16:00:38 +02:00
Christophe de Vienne 608fd976c4 Fix auto_increment on postgres database. 2016-06-20 15:00:19 +02:00
Jinzhu caa792644c Include model value when preloading many2many relations to enable row query callbacks 2016-06-17 18:18:46 +08:00
Jinzhu 18917d1f3e Merge pull request #1028 from nkovacs/wercker
Wercker postgres and mysql
2016-06-16 18:29:11 +08:00
Jinzhu 6ef2a539bd Fix test 2016-06-16 18:18:00 +08:00
Jinzhu 61f50a429a Fix preload has one relations 2016-06-16 17:58:25 +08:00
Jinzhu 277b4e93b6 Merge pull request #1013 from girokon/m2m_preload_issue
fix m2m nested preload
2016-06-16 16:41:34 +08:00
Jinzhu cf3f9927ae Merge pull request #1072 from jinzhu/revert-1064-jay/limit-offset
Revert "Use int64 for limit/offset values to ensure values > 32-bit int are addressable."
2016-06-16 16:32:24 +08:00
Jinzhu f926dd9f9f Revert "Use int64 for limit/offset values to ensure values > 32-bit int are addressable." 2016-06-16 16:31:50 +08:00