Commit Graph

2461 Commits

Author SHA1 Message Date
Jinzhu e4b130d2d7 Fix customize DeletedAt's column name 2017-02-01 21:33:36 +08:00
Jinzhu 89f6d74b5e Update isBlank checker 2017-01-25 17:42:15 +08:00
Jinzhu 7fb9b62c17 Apply Before('gorm:row_query') for row query callbacks w/o specify order for compatibility 2017-01-16 09:48:06 +08:00
Jinzhu a3b8b332ed Allow customize data type via ParseFieldStructForDialect 2017-01-15 21:45:17 +08:00
Jinzhu c62e9bcabe Query Row, Rows inside RowQuery callbacks 2017-01-15 18:03:12 +08:00
Jinzhu 97949fdbc1 Refactor Logger 2017-01-15 16:58:55 +08:00
Jinzhu 2c025b25fe Merge pull request #1256 from fobispo-link/master
Issue  #1249 fix - replacing $ placeholders in order when logging
2017-01-15 16:03:52 +08:00
Jinzhu 1aa2d4ca89 Fix primary key for embedded struct 2017-01-09 20:07:39 +08:00
Jinzhu 373207d546 Merge pull request #1304 from gernest/patch-1
Fix *Scope.buildNotCondition
2017-01-05 22:27:20 +08:00
Geofrey Ernest eb0880e710 Fix *Scope.buildNotCondition
this fixes the logic of handling empty slice of int family in a query i.e something linke `[]int64{}`

This code snipped doesn't look like it was intended to be this way

```
	if reflect.ValueOf(value).Len() > 0 {
			str = fmt.Sprintf("(%v.%v NOT IN (?))", scope.QuotedTableName(), scope.Quote(primaryKey))
			clause["args"] = []interface{}{value}
		}
		return ""
```

The `return ""` is always guaranteed to be executed regardless of whether the length of value is greater than 0. I believe the intended behavior is to return  `""` when the length of value is zero.
2017-01-05 10:38:39 +03:00
Jinzhu da8c2409ab Merge pull request #1299 from maximesong/master
fix typo
2017-01-04 17:41:28 +08:00
Maxime Song 58cbc9c4b5 fix typo 2017-01-04 15:53:49 +08:00
Jinzhu f828909983 Add how to support this project to README 2017-01-02 20:56:38 +08:00
Jinzhu af31cf33a3 Merge pull request #1287 from gernest/typo
Fix typo
2017-01-02 12:06:51 +08:00
gernest e651609eaa
Fix typo 2016-12-21 11:11:23 +03:00
Jinzhu 0fbff1e8f0 Merge pull request #1284 from sandalwing/master
Compile regexp ahead of time
2016-12-20 18:27:27 +08:00
Xavier Sandal 5a4dca7645 Compile regexp ahead of time
Signed-off-by: Xavier Sandal <sandalwing@sandalwing.com>
2016-12-19 22:36:13 -05:00
Jinzhu 0f2ceb5a77 Add gorm:association:source for association operations for plugins to extend GORM 2016-12-05 18:30:07 +08:00
Jinzhu eb06255b66 Skip order sql when quering with distinct 2016-12-01 16:16:20 +08:00
Jinzhu 066abcef40 Merge pull request #1132 from zardak/preload-dedupe 2016-11-10 09:33:15 +08:00
Francisco Obispo 7f328975cd When using the LogMode(true), the SQL produced during the log message, places the bounded variables in the wrong location, this is due to the fact that the current implementation splits the values with a regex similar to: ($\d+)|?.
That works well for ? placeholders because they should be replaced in order.

However, the numeric placeholders should be replaced based on their value, for instance:

SELECT name,last FROM contact WHERE name=$2 and age=$1
Should NOT be replaced in order, because it will yield an incorrectly formed SQL command, which is not very useful for debugging.

Fixes issue: #1249
2016-11-09 17:05:21 -08:00
Jinzhu 45fc640bf3 Merge pull request #1252 from slockij/block-global-update-delete
Block global updates / deletes
2016-11-10 08:45:29 +08:00
Jinzhu 53d09952be Fix AddError for DB 2016-11-09 10:22:42 +08:00
slockij e26cb8dbc4 In some cases (Error not checked, missed data) one can perform very harmful operation - global update or delete (all records)
This is to prevent it.
2016-11-04 17:54:43 +01:00
Jinzhu 9edd66250e Return error when creating with unaddressable record in postgres 2016-11-04 20:58:41 +08:00
Jinzhu d5d3e3a67b Merge pull request #1242 from calebthompson/make-errors-public
Make gorm.Errors available for use outside gorm
2016-11-03 21:47:49 +08:00
Jinzhu f2fe351aa0 Merge pull request #1243 from smacker/raw_first_last
db.Raw().First() makes wrong sql fix #1214
2016-11-03 21:45:29 +08:00
Jinzhu 4a540f3ac8 Add tag to support skip nested save for associations 2016-10-27 10:31:46 +08:00
smacker cf7fbb56d5 db.Raw().First() makes wrong sql fix #1214 2016-10-26 21:32:27 +07:00
Jinzhu 56a7d1b69e Change query's prefix table for generated conditions 2016-10-26 17:35:51 +08:00
Caleb Thompson c063624c91
Make gorm.Errors available for use outside gorm
gorm.Errors, which usefully implements `error` for an `[]error` as
returned by `DB.GetError()` was already exported, but because it used a
private field `errors`, it was not able to be created due to the
compile-time error:

    implicit assignment of unexported field 'errors' in gorm.Errors literal

The trivial solution would be to export the `errors` field on
`gorm.Errors`, but this led to the issue that the common pattern of
checking `err != nil` failed because a struct{error: nil} != nil.

We can take advantage of type aliasing here to make Errors an []error,
which can in fact be nil and would pass `err != nil` on the happy path.

* Remove `(Errors) GetErrors()`, as it's less useful when Errors is an
  []error which can be iterated over. While this is technically a
  breaking change, we never expose an Errors and its difficult to build
  one (it can be done with the existing `(Errors) Add(error)`), but
  awkwardly. This removal can be reverted without issue and we can make
  it an identity method, but it seemed an opportune time to reduce API
  surface area on something that likely isn't used.
* Remove errorsInterface, as it's not useful without `(Errors)
  GetErrors()`
* Change `(*Errors) Add(error)` => `(Errors) Add(error...) Errors`
  because we can't modify even a *Errors when it's a type alias. This is
  more idiomatic as it follows the pattern of `slice = append(slice,
  element)` Go developers are familiar with.
2016-10-25 11:22:50 -05:00
Jinzhu c1b9cf186e Merge pull request #1210 from baijum/error-zero-args
If no arguments, return error at once
2016-10-23 22:58:23 +08:00
Jinzhu 89b7cbe89c Fix RowsAffected not returned for FirstOrCreate 2016-10-21 11:30:17 +08:00
Jinzhu a667ab8427 Fix Replace has one/many associations 2016-10-20 13:27:26 +08:00
Jinzhu 5d853fc53c Fix null time not allowed in mysql5.7 test error 2016-10-19 12:20:45 +08:00
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