Changeset 6667
- Timestamp:
- 05/06/07 01:48:19 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb (modified) (3 diffs)
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/model/templates/migration.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6654 r6667 1 1 *SVN* 2 2 3 * Use association name for the wrapper element when using .to_xml. Previous behaviour lead to non-deterministic situations with STI and polymorphic associations. [Koz, jstrachan] 3 * Added short-hand declaration style to migrations (inspiration from Sexy Migrations, http://errtheblog.com/post/2381) [DHH]. Example: 4 5 create_table "products" do |t| 6 t.column "shop_id", :integer 7 t.column "creator_id", :integer 8 t.column "name", :string, :default => "Untitled" 9 t.column "value", :string, :default => "Untitled" 10 t.column "created_at", :datetime 11 t.column "updated_at", :datetime 12 end 13 14 ...can now be written as: 15 16 create_table :products do |t| 17 t.integer :shop_id, :creator_id 18 t.string :name, :value, :default => "Untitled" 19 t.timestamps 20 end 21 22 Note: Schema dumping still happens in the old style -- someone care to update it? 23 24 * Use association name for the wrapper element when using .to_xml. Previous behavior lead to non-deterministic situations with STI and polymorphic associations. [Koz, jstrachan] 4 25 5 26 * Improve performance of calling .create on has_many :through associations. [evan] trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
r6359 r6667 302 302 # This method returns <tt>self</tt>. 303 303 # 304 # == ===Examples304 # == Examples 305 305 # # Assuming td is an instance of TableDefinition 306 306 # td.column(:granted, :boolean) … … 323 323 # def.column(:huge_integer, :decimal, :precision => 30) 324 324 # #=> huge_integer DECIMAL(30) 325 # 326 # == Short-hand examples 327 # 328 # Instead of calling column directly, you can also work with the short-hand definitions for the default types. 329 # They use the type as the method name instead of as a parameter and allow for multiple columns to be defined 330 # in a single statement. 331 # 332 # What can be written like this with the regular calls to column: 333 # 334 # create_table "products", :force => true do |t| 335 # t.column "shop_id", :integer 336 # t.column "creator_id", :integer 337 # t.column "name", :string, :default => "Untitled" 338 # t.column "value", :string, :default => "Untitled" 339 # t.column "created_at", :datetime 340 # t.column "updated_at", :datetime 341 # end 342 # 343 # Can also be written as follows using the short-hand: 344 # 345 # create_table :products do |t| 346 # t.integer :shop_id, :creator_id 347 # t.string :name, :value, :default => "Untitled" 348 # t.timestamps 349 # end 350 # 351 # There's a short-hand method for each of the type values declared at the top. And then there's 352 # TableDefinition#timestamps that'll add created_at and updated_at as datetimes. 325 353 def column(name, type, options = {}) 326 354 column = self[name] || ColumnDefinition.new(@base, name, type) … … 334 362 end 335 363 364 %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type| 365 class_eval <<-EOV 366 def #{column_type}(*args) 367 options = args.last.is_a?(Hash) ? args.pop : {} 368 column_names = args 369 370 column_names.each { |name| column(name, '#{column_type}', options) } 371 end 372 EOV 373 end 374 375 def timestamps 376 column(:created_at, :datetime) 377 column(:updated_at, :datetime) 378 end 379 336 380 # Returns a String whose contents are the column definitions 337 381 # concatenated together. This string can then be pre and appended to trunk/railties/CHANGELOG
r6627 r6667 1 1 *SVN* 2 3 * Updated resource_scaffold and model generators to use short-hand style migrations [DHH] 2 4 3 5 * Updated initializer to only load #{RAILS_ENV}.rb once. Added deprecation warning for config.breakpoint_server. [Nicholas Seckar] trunk/railties/lib/rails_generator/generators/components/model/templates/migration.rb
r5236 r6667 3 3 create_table :<%= table_name %> do |t| 4 4 <% for attribute in attributes -%> 5 t. column :<%= attribute.name %>, :<%= attribute.type %>5 t.<%= attribute.type %> :<%= attribute.name %> 6 6 <% end -%> 7 7 end trunk/railties/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb
r5147 r6667 3 3 create_table :<%= table_name %> do |t| 4 4 <% for attribute in attributes -%> 5 t. column :<%= attribute.name %>, :<%= attribute.type %>5 t.<%= attribute.type %> :<%= attribute.name %> 6 6 <% end -%> 7 7 end