Commit Graph

1302 Commits

Author SHA1 Message Date
Jinzhu b7554a2cb0 Fix delete many2many associations 2015-01-16 10:15:53 +08:00
Jinzhu ebe5f191a9 Fix upper case for primary key 2015-01-16 10:02:04 +08:00
Jinzhu 0d0e8d651d Merge branch 'jaytaylor-postgres-quoting' 2015-01-14 07:59:29 +08:00
Jinzhu aa8bc02c11 Fix broken test for postgres 2015-01-14 07:59:21 +08:00
Jinzhu e3327d0800 Merge pull request #338 from likestripes/is_ignored_fix
check isIgnored when compiling attrs to update
2015-01-14 07:58:02 +08:00
Travis Donia 73c47b90fe check isIgnored when compiling attrs to update 2015-01-14 07:53:09 +08:00
Jay Taylor 2166649409 Ensure identifiers are quoted for `RETURNING` and `DROP INDEX` statements. 2015-01-13 15:27:35 -08:00
Travis Donia 3aac11abc8 check isIgnored when compiling attrs to update 2015-01-13 17:57:47 -05:00
Jinzhu 016e91db20 Merge pull request #336 from bramp/deleted-at-join-issue-335
Fixes #335 - Added scoped table name to "deleted_at" where clause. This ...
2015-01-12 10:50:46 +08:00
Andrew Brampton fef286a7bc Fixes #335 - Added scoped table name to "deleted_at" where clause. This ensures it works when the deleted_at column is ambigious, for example, during a join. 2015-01-11 13:49:36 -08:00
Jinzhu 3500dfa1b6 expose db.New as API 2015-01-06 15:11:41 +08:00
Jinzhu 1b4490fd47 Add MIT License file 2015-01-05 08:59:18 +08:00
Jinzhu 1e6e785651 Fix return incorrect sql type 2015-01-05 08:43:13 +08:00
Jinzhu 61d2ccb764 Merge pull request #327 from xconstruct/master
Fix error when chaining empty where conditions
2015-01-05 07:50:45 +08:00
Constantin Schomburg 045b4d6d2a Fix error when chaining empty where conditions 2015-01-04 13:47:25 +01:00
Jinzhu 0219fb1cc0 Don't raise error if no record found when find all 2014-12-19 11:50:34 +08:00
Jinzhu 6f2e92e136 Merge pull request #318 from galeone/master
Fixes #317
2014-12-18 10:05:53 +08:00
Paolo Galeone d60322978a Fixes https://github.com/jinzhu/gorm/issues/317 2014-12-17 22:41:00 +01:00
Jinzhu 5c9d3bb352 Merge branch 'galeone-master' 2014-12-13 10:46:25 +08:00
Jinzhu 5823670269 Refactor callbck_create 2014-12-13 10:46:16 +08:00
Paolo Galeone e30cf3bbd1 Fix number of columns affected. Is always one. The old parameter was the numer of fields affected 2014-12-08 20:33:31 +01:00
Paolo Galeone 907ea93b43 Fixes scan when primary key is not defined in gorm (but is defined db-size). Useful in join tables 2014-12-08 19:00:02 +01:00
Paolo Galeone 21f4de584f Use tableName.field or tableName.* in returning string 2014-12-08 12:03:42 +01:00
Paolo Galeone 0fa1335555 Avoid Errors in postgres when creating a row without a GORM defined primary key (but defined db-side) 2014-12-08 11:33:30 +01:00
Jinzhu cbcb88d3d1 Fix set ForeignKey for embedded struct 2014-12-04 11:44:00 +08:00
Jinzhu 6d13ae4ead Merge pull request #303 from jnfeinstein/dev_poly
Support polymorphic has-one and has-many associations
2014-11-28 10:10:47 +08:00
Jinzhu 1cb6e5664e Merge pull request #305 from jnfeinstein/master
Fields are cached when withRelation, so they should only be accessed when withRelation.
2014-11-28 08:33:11 +08:00
jnfeinstein a8492826a8 Fields are only cached when withRelation, so they should only be accessed when withRelation.
The result of .Fields() is quite different with and without withRelation.
I assume that if you call it without withRelation, you don't want the
fields that were cached when withRelation was true.
2014-11-27 14:04:05 -08:00
Jinzhu 13c1b44804 Merge pull request #300 from jnfeinstein/master
.Count() should always use ToSnake'd foreign keys.
2014-11-26 17:12:16 +08:00
jnfeinstein 8b451f0084 Add support for polymorphic relationships using the POLYMORPHIC setting.
This commit adds support for two settings:

FOREIGNTYPE - A field that is used to store the type of the owner.

POLYMORPHIC - A shortcut to set FOREIGNKEY and FOREIGNTYPE to the same
value suffixed by "Id" and "Type" respectively.

The type is stored as the table name, which I thought might be useful
for other queries.

The biggest gotcha of this commit is that I flipped the definition of
has_one and belongs_to. gorm is very flexible such that it didn't
really care if it was a has_one or belongs_to, and can pretty much
determine it at runtime. For the sake of the error, I had to define
one of them as belongs_to, and I chose the one with the fields as
the belongs_to, like ActiveRecord. The error could probably be
genericized to "gorm cannot determine type", but I think it's nicer
to tell people DONT DO PATTERN XYZ CAUSE IT WONT WORK. Functionally,
it doesn't matter.
2014-11-25 21:35:47 -08:00
jnfeinstein 1de020dc4d Add test for polymorphic associations. 2014-11-25 21:27:08 -08:00
jnfeinstein 7e8c0f7edd Add README.md updates for polymorphism. 2014-11-25 21:27:08 -08:00
jnfeinstein 794e1ba20b .Count() should always use ToSnake'd foreign keys.
It looks like gorm always uses the snake form of a column by
convention, as seen by searching DBName in scope.go. These counts
were erroring out without the ToSnake'd foreign keys.

Further, the code for has_many and has_one becomes the same (which
makes sense), so I combined the two cases.
2014-11-25 11:47:23 -08:00
Jinzhu a4e0ef6509 Refactor reuse existing database connection 2014-11-25 15:21:28 +08:00
jnfeinstein 1d6b59f223 Allow .Open to reuse existing database connections.
This commit allows you to pass a string or an existing database
connection as the source for gorm. The dialect is still required
because a) there is no common reference to it as far as i know, and
b) gorm allows the dialect to differ from the driver. So, for the sake
of simplicity, you still have to specity the dialect.

This is useful if you have an existing transaction, but still
want to use gorm to format your queries.

This is dependent on the defintion of DB in pkg database/sql having
the field 'dsn', which is the database source, obtained via reflect.
2014-11-25 15:21:28 +08:00
Jinzhu 0e22837c04 Merge pull request #297 from westonplatter/readme-add-wrecker
readme. add wrecker master branch badge to readme.
2014-11-25 15:15:08 +08:00
Jinzhu a7e63541fd Fix migration tests 2014-11-25 14:41:09 +08:00
Jinzhu e9684db42a Show error message if not using addressable value for auto migration 2014-11-25 13:44:14 +08:00
Jinzhu 1aaac379ae Fix tests for mysql, postgres 2014-11-24 18:16:07 +08:00
Weston Platter e56f82e256 readme. add wrecker master branch badge to readme. 2014-11-23 21:38:57 -07:00
Jinzhu 84954e6779 Merge pull request #284 from shirou/master
fix panic problem when the struct has unexported field.
2014-11-21 10:29:55 +08:00
Shirou WAKAYAMA e313827f04 fix panic problem when the struct has unexported field. 2014-11-19 12:44:57 +09:00
Jinzhu f43456fecf Merge pull request #282 from jnfeinstein/master
Add additional methods of specifying the 'select' portion of a query.
2014-11-18 20:34:24 +08:00
jnfeinstein 429a100856 Add additional methods of specifying the 'select' portion of a query.
This commit adds more ways of specifying selects:

-) You can now pass in a []string.  This is mostly for convenience,
since you may want to dynamically create a list of fields to be
selected.

-) You can now use variables.  This is important because a select
could take user input.  For example, finding a MAX between a record
and a given number could be easily done using select, and then
you don't have to process anything in backend logic.  This is also
necessary to use postgres text search capabilities (which actaully
play nicely with the rest of gorm).

-) You can now chain select calls.  This could be useful in
conjunction with gorm's scopes functionality.
2014-11-17 07:36:26 -05:00
ryanss 62b447bc9a Create tables with fields in same order as defined in struct 2014-11-17 07:36:26 -05:00
Jinzhu 8482d0a121 Merge pull request #280 from ryanss/master
Create tables with fields in same order as defined in struct
2014-11-17 17:50:09 +08:00
Jinzhu 75819b2bb3 Refactor DefaultValue 2014-11-17 17:38:32 +08:00
ryanss d3097687f7 Create tables with fields in same order as defined in struct 2014-11-16 00:42:36 -05:00
Paolo Galeone 064d91335b Add default values support ( https://github.com/jinzhu/gorm/issues/251 ) 2014-11-15 18:32:35 +01:00
Jinzhu a405f08f3a Merge branch 'BugHert push origin master-fix-one-to-one-relation' 2014-11-12 10:25:43 +08:00