aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRobin Dupret <robin.dupret@gmail.com>2012-07-04 17:26:19 +0300
committerRobin Dupret <robin.dupret@gmail.com>2012-07-04 19:15:31 +0200
commit2f6004de6e692da81237a4d978b273acfbc9f396 (patch)
tree1930ceb03cc656deffcf986dd5657864960af281 /railties
parentb5a2f24b6b2b466a5692f0d46b4a2b8154ee0e53 (diff)
downloadrails-2f6004de6e692da81237a4d978b273acfbc9f396.tar.gz
rails-2f6004de6e692da81237a4d978b273acfbc9f396.tar.bz2
rails-2f6004de6e692da81237a4d978b273acfbc9f396.zip
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`