Commit Graph

150 Commits

Author SHA1 Message Date
Jinzhu f8e4e16e09 Fix Where with string 2015-01-20 11:30:01 +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 1e6e785651 Fix return incorrect sql type 2015-01-05 08:43:13 +08:00
Constantin Schomburg 045b4d6d2a Fix error when chaining empty where conditions 2015-01-04 13:47:25 +01: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
Jinzhu 1aaac379ae Fix tests for mysql, postgres 2014-11-24 18:16:07 +08:00
Shirou WAKAYAMA e313827f04 fix panic problem when the struct has unexported field. 2014-11-19 12:44:57 +09: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 b1c2a22646 Remove unnecessary ToSnake 2014-11-12 10:23:54 +08:00
Paolo Galeone da3e74ba6f Add support for signed and unsigned integer types as primary key type 2014-11-12 10:09:06 +08:00
deoxxa c041e53612 fix query generation for one-to-one relations 2014-11-06 10:52:23 +11:00
Tristan Storch 9bee4239d4 FieldValueByName does now only what it should
FieldValueByName in utils.go does now only what it should and has proper errors.
2014-10-01 16:20:12 +02:00
Joel Trost a6b243a3e9 fix for bad rebase 2014-09-16 14:49:29 -07:00
Joel Trost 6b7d0879c5 Ran gofmt and removed panic statements
Unnecessary panics in create_test and delete_test removed
2014-09-16 14:24:55 -07:00
Joel Trost f79e1a2ef6 GORM support for MSSQL, passes all tests 2014-09-16 14:21:35 -07:00
Jinzhu 0f3a9a8d02 Support include struct type in the foreign key to avoid ambiguous 2014-09-08 11:19:25 +08:00
Jinzhu 953c347ba7 Refactor Scope 2014-09-02 19:03:01 +08:00
Jinzhu 6271cf0e55 Fix tests for postgres 2014-08-30 22:39:28 +08:00
Cihangir SAVAS 4e90fbf4e8 gorm: added ability to change the time.now format 2014-08-23 01:00:04 -07:00
Jinzhu febc826511 Don't check relations if field is ignored 2014-08-14 21:54:23 +08:00
Shirou WAKAYAMA 5ad9306146 Add DropTableIfExists. 2014-08-05 23:14:40 +09:00
Jinzhu 8308491d9a Fix AutoMigrate with nested Scanner 2014-08-04 14:37:51 +08:00
Jinzhu 90106d82c5 Export Relationship 2014-07-31 14:38:16 +08:00
Jinzhu 2356182ea7 Rename joinTable to relationship 2014-07-30 20:59:52 +08:00
Jinzhu e1e68debdc improve association 2014-07-30 20:48:36 +08:00
Jinzhu 0d3085393e Add IndirectValue for Scope 2014-07-30 14:58:00 +08:00
Jinzhu 371e6af99e Create join table when run AutoMigrate 2014-07-30 14:20:38 +08:00
Jinzhu 14590a65dc Save many to many relations into join table 2014-07-30 14:18:15 +08:00
Jinzhu f56e071375 Refact parse SQL tag, set default size to 255 2014-07-29 17:52:23 +08:00
Jinzhu 2bffb43138 Write stub code for Many2Many 2014-07-29 17:28:10 +08:00
Jinzhu b929a082d7 Fix remove index for sqlite and postgres 2014-07-29 12:02:03 +08:00
Jinzhu 2d3bcf5297 Refact untils.go 2014-07-25 16:53:28 +08:00
Jinzhu 40c16f3c29 Export method ToSnake and SnakeToUpperCamel 2014-07-21 14:06:54 +08:00
Jinzhu 325e6c2ef1 Fix tests with go v1.3 2014-07-02 11:56:44 +08:00
Jinzhu 0cba662be0 Add method QuotedTableName for Scope 2014-06-03 17:17:30 +08:00
Jinzhu 2fff8a7fac Revert "quote table name"
This reverts commit 38a06bfdaa.
2014-06-03 17:16:34 +08:00
Vladimir Garvardt d1dc0ccbef AddUniqueIndex 2014-06-01 02:35:56 +04:00
Vladimir Garvardt cdce84fd1a AddIndex for multiple columns 2014-06-01 02:26:17 +04:00
Jinzhu 38a06bfdaa quote table name 2014-05-24 09:54:17 +08:00
Jinzhu 66e6c9af9f Add method HasTable, HasColumn to dialect 2014-04-25 09:08:48 +08:00
Jinzhu 288c8e37af Merge branch 'sunfmin-master'
Conflicts:
	main.go
2014-04-25 07:23:26 +08:00
Felix Sun 1ff3c79c75 When multiple databases have the same table name and column names, automigrate doesn't work 2014-04-25 00:39:38 +08:00
Paolo Galeone bcb1ca67c0 Add support for primary key different from id 2014-04-06 04:10:45 +02:00
Jinzhu 1949baf5c8 Test Related with search conditions 2014-03-26 08:48:40 +08:00
Jinzhu e6c953dd4c Support custom types from base types 2014-03-16 09:58:32 +08:00
Jinzhu 24d527670b Use the same database for Related 2014-03-07 19:08:33 +08:00
Jinzhu 2c33502503 Add tests for updated_at will be updated when update value with Assign 2014-02-18 10:03:14 +08:00
Jinzhu c25f26149e Fix comparing uncomparable type error 2014-01-30 16:41:10 +08:00
Jinzhu 5eed96457b rename couple of scope related methods 2014-01-29 12:00:57 +08:00