aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-07-05 05:38:05 -0700
committerJosé Valim <jose.valim@plataformatec.com.br>2012-07-05 05:38:05 -0700
commit5534733f69d36312b1a4e34dee61b41504a2c9e2 (patch)
tree04d143a05b5ecbccb3c22282dbe655e64a3d56dd /railties
parent6c9c50c30fe2e9a0e39216801f96b52a2df3097d (diff)
parent2f6004de6e692da81237a4d978b273acfbc9f396 (diff)
downloadrails-5534733f69d36312b1a4e34dee61b41504a2c9e2.tar.gz
rails-5534733f69d36312b1a4e34dee61b41504a2c9e2.tar.bz2
rails-5534733f69d36312b1a4e34dee61b41504a2c9e2.zip
Merge pull request #6959 from robin850/patch-1
Add few information on the field types
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/model/USAGE49
1 files changed, 49 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE
index 67f76aad01..c46c86076e 100644
--- a/railties/lib/rails/generators/rails/model/USAGE
+++ b/railties/lib/rails/generators/rails/model/USAGE
@@ -19,6 +19,55 @@ Description:
then the generator will create a module with a table_name_prefix method
to prefix the model's table name with the module name (e.g. admin_account)
+Available field types:
+
+ Just after the field name you can specify a type like text or boolean.
+ It will generate the column with the associated SQL type. For instance:
+
+ `rails generate model post title:string body:text`
+
+ will generate a title column with a varchar type and a body column with a text
+ type. You can use the following types:
+
+ integer
+ primary_key
+ decimal
+ float
+ boolean
+ binary
+ string
+ text
+ date
+ time
+ datetime
+ timestamp
+
+ You can also consider `references` as a kind of type. For instance, if you run:
+
+ `rails generate model photo title:string album:references`
+
+ It will generate an album_id column. You should generate this kind of fields when
+ you will use a `belongs_to` association for instance. `references` also support
+ the polymorphism, you could enable the polymorphism like this:
+
+ `rails generate model product supplier:references{polymorphic}`
+
+ You can also specify some options just after the field type. You can use the
+ following options:
+
+ limit Set the maximum size of the field giving a number between curly braces
+ default Set a default value for the field
+ precision Defines the precision for the decimal fields
+ scale Defines the scale for the decimal fields
+ uniq Defines the field values as unique
+ index Will add an index on the field
+
+ Examples:
+
+ `rails generate model user pseudo:string{30}`
+ `rails generate model user pseudo:string:uniq`
+
+
Examples:
`rails generate model account`