Commit Graph

30 Commits

Author SHA1 Message Date
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
Paolo Galeone 064d91335b Add default values support ( https://github.com/jinzhu/gorm/issues/251 ) 2014-11-15 18:32:35 +01:00
Tristan Storch f1212ecd58 Readability update
Small readability update. Includes also a switch from bool return values to
error return values in Scope.SetColumn and Field.Set.
2014-09-30 14:02:51 +02:00
Jinzhu 59846f0e9b Fix tests for association 2014-09-02 20:10:18 +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
Jinzhu d806b7084f Pass anonymous struct tests 2014-08-30 21:42:35 +08:00
Jinzhu 90106d82c5 Export Relationship 2014-07-31 14:38:16 +08:00
Jinzhu 6c4b635176 Replace BeforeAssociation, AfterAssociation with association type 2014-07-30 21:14:10 +08:00
Jinzhu 2356182ea7 Rename joinTable to relationship 2014-07-30 20:59:52 +08:00
Jinzhu a7aaf151cf Use JoinTable instead of ForeignKey 2014-07-30 11:32:18 +08:00
Jinzhu f56e071375 Refact parse SQL tag, set default size to 255 2014-07-29 17:52:23 +08:00
Jinzhu 2d3bcf5297 Refact untils.go 2014-07-25 16:53:28 +08:00
Jinzhu 67b9e2a9ad Fix typo 2014-07-25 15:49:23 +08:00
Chris Aumann 4772acb1c4 Add basic support for DEFAULT values 2014-07-21 23:37:40 +02:00
Jinzhu 241b6bc3b9 refact 2014-01-29 10:35:28 +08:00
Jinzhu a2edf56c58 Remove unused codes 2014-01-28 16:06:22 +08:00
Jinzhu 3981baf65d Make callback create pass all tests 2014-01-27 10:47:37 +08:00
Jinzhu ee6a6827a8 implement callback shared 2014-01-27 08:26:59 +08:00
Jinzhu 8dd7b4ed91 make callback create works 2014-01-26 19:36:15 +08:00
Jinzhu 2409c26710 Ignore association with sql tag 2014-01-23 08:50:39 +08:00
Jinzhu 0208ce7901 Fix []byte type 2013-11-21 13:47:49 +08:00
Jinzhu bf1db1534e Use channel to make gorm faster 2013-11-17 09:50:34 +08:00
Jinzhu 9a1c0d956d cache snake, upper values 2013-11-17 08:28:30 +08:00
Jinzhu 0ad707b410 Yay, all tests passed 2013-11-16 18:42:47 +08:00
Jinzhu ca6b074dc6 Refact do 2013-11-16 13:28:22 +08:00
Jinzhu 045b3b6fbc Fix errors in field.go, model.go 2013-11-16 12:22:18 +08:00
Jinzhu 2d34ecd6a9 Refact Code 2013-11-15 11:36:27 +08:00
Jinzhu c354b0fb06 Refact field struct 2013-11-14 22:12:32 +08:00
Jinzhu e4612bde9c Separate Field Struct 2013-11-14 21:26:02 +08:00