Commit Graph

74 Commits

Author SHA1 Message Date
Jinzhu eb480cc085 Modify struct when update association 2015-02-24 18:48:48 +08:00
Jinzhu 0d2c37e310 Refactor Model Struct 2015-02-18 12:50:37 +08:00
Jinzhu 5c478b46e1 Use Common Initialisms from golint 2015-02-18 10:36:32 +08:00
Jinzhu 672ba4ffc9 Rename ToSnake to ToDBColumnName 2015-02-18 09:26:35 +08:00
Jinzhu 0b32041135 Review and Refactor 2015-02-17 22:55:14 +08:00
Jinzhu 38cbff9c79 Refactor Associations 2015-02-17 20:19:47 +08:00
Jinzhu 00d1187c4c Refactor Association 2015-02-17 19:17:21 +08:00
Jinzhu 2a8c7973cb Use new relationship API 2015-02-17 18:57:50 +08:00
Jinzhu f4e705b749 Fix compile error 2015-02-16 16:42:01 +08:00
Jinzhu 6864d5e5bd Add polymorphic_test.go 2015-02-13 11:26:02 +08:00
Jinzhu 8aef600540 Fix association Replace delete wrong records 2015-02-09 21:54:16 +08:00
Jinzhu b7554a2cb0 Fix delete many2many associations 2015-01-16 10:15:53 +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 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
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
Jinzhu 953c347ba7 Refactor Scope 2014-09-02 19:03:01 +08:00
Jinzhu 90106d82c5 Export Relationship 2014-07-31 14:38:16 +08:00
Jinzhu ba74a9545b Make clear works 2014-07-30 22:15:31 +08:00
Jinzhu 5a95050464 Make association replace works 2014-07-30 22:10:12 +08:00
Jinzhu db3da2c636 Make association Count works 2014-07-30 21:43:53 +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 efd3b7678b Be able to find many to many relations 2014-07-30 16:22:26 +08:00
Jinzhu ba95de5c50 Rename relations to associations 2014-07-30 14:30:21 +08:00