Skip to content
This repository
Browse code

Add few information on the field types

  • Loading branch information...
commit 2f6004de6e692da81237a4d978b273acfbc9f396 1 parent b5a2f24
Robin Dupret authored July 04, 2012
49  railties/lib/rails/generators/rails/model/USAGE
@@ -19,6 +19,55 @@ Description:
19 19
     then the generator will create a module with a table_name_prefix method
20 20
     to prefix the model's table name with the module name (e.g. admin_account)
21 21
 
  22
+Available field types:
  23
+
  24
+    Just after the field name you can specify a type like text or boolean. 
  25
+    It will generate the column with the associated SQL type. For instance:
  26
+
  27
+        `rails generate model post title:string body:text`
  28
+
  29
+    will generate a title column with a varchar type and a body column with a text 
  30
+    type. You can use the following types:
  31
+
  32
+        integer
  33
+        primary_key
  34
+        decimal
  35
+        float
  36
+        boolean
  37
+        binary
  38
+        string
  39
+        text
  40
+        date
  41
+        time
  42
+        datetime
  43
+        timestamp
  44
+
  45
+    You can also consider `references` as a kind of type. For instance, if you run:
  46
+
  47
+        `rails generate model photo title:string album:references`
  48
+
  49
+    It will generate an album_id column. You should generate this kind of fields when
  50
+    you will use a `belongs_to` association for instance. `references` also support
  51
+    the polymorphism, you could enable the polymorphism like this:
  52
+
  53
+        `rails generate model product supplier:references{polymorphic}`
  54
+
  55
+    You can also specify some options just after the field type. You can use the
  56
+    following options:
  57
+
  58
+        limit        Set the maximum size of the field giving a number between curly braces
  59
+        default      Set a default value for the field
  60
+        precision    Defines the precision for the decimal fields 
  61
+        scale        Defines the scale for the decimal fields
  62
+        uniq         Defines the field values as unique 
  63
+        index        Will add an index on the field
  64
+
  65
+    Examples:
  66
+
  67
+        `rails generate model user pseudo:string{30}`
  68
+        `rails generate model user pseudo:string:uniq`
  69
+        
  70
+
22 71
 Examples:
23 72
     `rails generate model account`
24 73
 

0 notes on commit 2f6004d

Please sign in to comment.
Something went wrong with that request. Please try again.