You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ class CreatePictures < ActiveRecord::Migration
29
29
end
30
30
```
31
31
32
-
The problem with this approach is the`imageable_type` is a string (and by default it is 255 characters). This is a little rediculous. For comparison, if we had a state machine with X states, would be describe the states with strings `"State1", "State2", etc` or would be just enumerate the state column and make it an integer. This gem will make it so we can use an integer for the `imageable_type` column.
32
+
The problem with this approach is that`imageable_type` is a string (and by default it is 255 characters). This is a little ridiculous. For comparison, if we had a state machine with X states, would we describe the states with strings `"State1", "State2", etc` or would we just enumerate the state column and make it an integer? This gem will allow us to use an integer for the `imageable_type` column.
33
33
34
34
## Installation
35
35
@@ -49,7 +49,7 @@ Or install it yourself as:
49
49
50
50
The gem is pretty straightforward to use.
51
51
52
-
First, include the extensions module and add the `integer_type` option to the assocaitions that are going to be using this. (That way it will play nicely with polymorphic association you would rather the type remain as a string)
52
+
First, include the extensions module and add the `integer_type` option to the associations that are going to be using this. (That way it will play nicely with polymorphic associations whose type you would rather leave as a string.)
53
53
```ruby
54
54
classPicture < ActiveRecord::Base
55
55
includePolymorphicIntegerType::Extensions
@@ -76,9 +76,9 @@ PolymorphicIntegerType::Mapping.configuration do |config|
76
76
end
77
77
```
78
78
79
-
Note: The mapping here can start from whatever integer you wish, but I would advise not to use 0. The reason being that if you had a new class, for instance `Avatar`, and also wanted to use this polymorphic association but forgot to include it in the mapping, it would effectively get `to_i` called on it and stored in the database. `"Avatar".to_i == 0` so if your mapping included 0, this would create a weird bug.
79
+
Note: The mapping here can start from whatever integer you wish, but I would advise not using 0. The reason being that if you had a new class, for instance `Avatar`, and also wanted to use this polymorphic association but forgot to include it in the mapping, it would effectively get `to_i` called on it and stored in the database. `"Avatar".to_i == 0`, so if your mapping included 0, this would create a weird bug.
80
80
81
-
If you want to migrate from a polymorphic association that is already a string you'll need to setup a migration (assuming sql for the time being. But this should be pretty straightforward)
81
+
If you want to convert a polymorphic association that is already a string, you'll need to set up a migration. (Assuming SQL for the time being, but this should be pretty straightforward.)
@@ -122,7 +122,7 @@ class PictureToPolymorphicIntegerType < ActiveRecord::Migration
122
122
end
123
123
```
124
124
125
-
Lastly, you will need to be careful of any place where you are doing raw sql queries with the string (`imageable_type = 'Employee'`). They should use the integer instead
125
+
Lastly, you will need to be careful of any place where you are doing raw SQL queries with the string (`imageable_type = 'Employee'`). They should use the integer instead.
0 commit comments