* Support bulk change_table in mysql2 adapter, as well as the mysql one. *Jon Leighton*

229

230

* If multiple parameters are sent representing a date, and some are blank, the

231

resulting object is nil. In previous releases those values defaulted to 1. This only affects existing but blank parameters, missing ones still raise an error. [Akira Matsuda]

232

* ActiveRecord::Base.establish_connection now takes a string that contains

233

a URI that specifies the connection configuration. For example:

234

ActiveRecord::Base.establish_connection 'postgres://localhost/foo'

235

236

* Active Record's dynamic finder will now raise the error if you passing in less number of arguments than what you call in method signature.

237

238

So if you were doing this and expecting the second argument to be nil:

239

240

User.find_by_username_and_group("sikachu")

241

242

You'll now get `ArgumentError: wrong number of arguments (1 for 2).` You'll then have to do this:

243

244

User.find_by_username_and_group("sikachu", nil)

245

246

*Prem Sichanugrist*

247

248

249

## Rails 3.1.0 (August 30, 2011) ##

250

251

* Add a proxy_association method to association proxies, which can be called by association

252

extensions to access information about the association. This replaces proxy_owner etc with

253

proxy_association.owner.

254

255

*Jon Leighton*

256

257

* ActiveRecord::MacroReflection::AssociationReflection#build_record has a new method signature.

258

259

Before: def build_association(*options)

260

After: def build_association(*options, &block)

261

262

Users who are redefining this method to extend functionality should ensure that the block is

263

passed through to ActiveRecord::Base#new.

264

265

This change is necessary to fix https://github.com/rails/rails/issues/1842.

266

267

*Jon Leighton*

268

269

* AR#pluralize_table_names can be used to singularize/pluralize table name of an individual model:

270

271

class User < ActiveRecord::Base

272

self.pluralize_table_names = false

273

end

274

275

Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. *Guillermo Iguaran*

276

277

* Add block setting of attributes to singular associations:

278

279

class User < ActiveRecord::Base

280

has_one :account

281

end

282

283

user.build_account{ |a| a.credit_limit => 100.0 }

284

285

The block is called after the instance has been initialized. *Andrew White*

286

287

* Add ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or table does not exists. *Prem Sichanugrist*

288

289

* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0

290

291

* AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes! all accept a second hash as option that allows you

292

to specify which role to consider when assigning attributes. This is built on top of ActiveModel's

293

new mass assignment capabilities:

294

295

class Post < ActiveRecord::Base

296

attr_accessible :title

297

attr_accessible :title, :published_at, :as => :admin

298

end

299

300

Post.new(params[:post], :as => :admin)

301

302

assign_attributes() with similar API was also added and attributes=(params, guard) was deprecated.

303

304

Please note that this changes the method signatures for AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes!. If you have overwritten these methods you should update them accordingly.

305

306

*Josh Kalderimis*

307

308

* default_scope can take a block, lambda, or any other object which responds to `call` for lazy

309

evaluation:

310

311

default_scope { ... }

312

default_scope lambda { ... }

313

default_scope method(:foo)

314

315

This feature was originally implemented by Tim Morgan, but was then removed in favour of

316

defining a 'default_scope' class method, but has now been added back in by Jon Leighton.

317

The relevant lighthouse ticket is #1812.

318

319

* Default scopes are now evaluated at the latest possible moment, to avoid problems where

320

scopes would be created which would implicitly contain the default scope, which would then

321

be impossible to get rid of via Model.unscoped.

322

323

Note that this means that if you are inspecting the internal structure of an

324

ActiveRecord::Relation, it will *not* contain the default scope, though the resulting

325

query will do. You can get a relation containing the default scope by calling

326

ActiveRecord#with_default_scope, though this is not part of the public API.

327

328

*Jon Leighton*

329

330

* If you wish to merge default scopes in special ways, it is recommended to define your default

331

scope as a class method and use the standard techniques for sharing code (inheritance, mixins,

332

etc.):

333

334

class Post < ActiveRecord::Base

335

def self.default_scope

336

where(:published => true).where(:hidden => false)

337

end

338

end

339

340

*Jon Leighton*

341

342

* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.

343

344

* ConnectionManagement middleware is changed to clean up the connection pool

345

after the rack body has been flushed.

346

347

* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks.

348

It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of

349

the updated_at column. It should not be called on new records.

350

Example:

351

352

User.first.update_column(:name, "sebastian") # => true

353

354

*Sebastian Martinez*

355

356

* Associations with a :through option can now use *any* association as the

357

through or source association, including other associations which have a

358

:through option and has_and_belongs_to_many associations

359

360

*Jon Leighton*

361

362

* The configuration for the current database connection is now accessible via

363

ActiveRecord::Base.connection_config. *fxn*

364

365

* limits and offsets are removed from COUNT queries unless both are supplied.

* Calling ActiveRecord::Base#clone will result in a shallow copy of the record,

527

including copying the frozen state. No callbacks will be called.

528

* Calling ActiveRecord::Base#dup will duplicate the record, including calling

529

after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.

530

* Migrations can be defined as reversible, meaning that the migration system

531

will figure out how to reverse your migration. To use reversible migrations, just define the "change" method. For example:

532

class MyMigration < ActiveRecord::Migration

533

def change

534

create_table(:horses) do

535

t.column :content, :text

536

t.column :remind_at, :datetime

537

end

538

end

539

end

540

541

Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in `change` that cannot be reversed, an IrreversibleMigration exception will be raised when going down.

* Remove support for SQLite 2. Please upgrade to SQLite 3+ or install the plugin from git://github.com/rails/sqlite2_adapter.git *Pratik Naik*

862

863

* PostgreSQL: XML datatype support. #1874*Leonardo Borges*

864

865

* quoted_date converts time-like objects to ActiveRecord::Base.default_timezone before serialization. This allows you to use Time.now in find conditions and have it correctly be serialized as the current time in UTC when default_timezone == :utc. #2946*Geoff Buesing*

* before_save, before_validation and before_destroy callbacks that return false will now ROLLBACK the transaction. Previously this would have been committed before the processing was aborted. #891*Xavier Noria*

* Partial updates include only unsaved attributes. Off by default; set YourClass.partial_updates = true to enable. *Jeremy Kemper*

1061

1062

* Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled *Geoff Buesing*

1063

1064

* Fixed that validates_size_of :within works in associations #11295, #10019*cavalle*

1065

1066

* Track changes to unsaved attributes. *Jeremy Kemper*

1067

1068

* Switched to UTC-timebased version numbers for migrations and the schema. This will as good as eliminate the problem of multiple migrations getting the same version assigned in different branches. Also added rake db:migrate:up/down to apply individual migrations that may need to be run when you merge branches #11458*John Barnette*

* Removed query cache rescue as it could cause code to be run twice (closes #10408) *David Heinemeier Hansson*

1203

1204

1205

## 2.0.0 (December 6th, 2007) ##

1206

1207

* Anchor DateTimeTest to fixed DateTime instead of a variable value based on Time.now#advance#to_datetime, so that this test passes on 64-bit platforms running Ruby 1.8.6+ *Geoff Buesing*

1208

1209

* Fixed that the Query Cache should just be ignored if the database is misconfigured (so that the "About your applications environment" works even before the database has been created) *David Heinemeier Hansson*

1210

1211

* Fixed that the truncation of strings longer than 50 chars should use inspect

1212

so newlines etc are escaped #10385 [Norbert Crombach]

1213

* Fixed that habtm associations should be able to set :select as part of their definition and have that honored *David Heinemeier Hansson*

1214

1215

* Document how the :include option can be used in Calculations::calculate. Closes #7446*adamwiggins, ultimoamore*

* Allow change_column to set NOT NULL in the PostgreSQL adapter *Tarmo Tänav*

1345

1346

* Fix that ActiveRecord would create attribute methods and override custom attribute getters if the method is also defined in Kernel.methods. *Rick Olson*

1347

1348

* Don't call attr_readonly on polymorphic belongs_to associations, in case it matches the name of some other non-ActiveRecord class/module. *Rick Olson*

1349

1350

* Try loading activerecord-<adaptername>-adapter gem before trying a plain require so you can use custom gems for the bundled adapters. Also stops gems from requiring an adapter from an old Active Record gem. *Jeremy Kemper, Derrick Spell*

- Generate Reader and Writer methods which cache attribute values in hashes. This is to avoid repeatedly parsing the same date or integer columns. - Change exception raised when users use find with :select then try to access a skipped column. Plugins could override missing_attribute() to lazily load the columns. - Move method definition to the class, instead of the instance - Always generate the readers, writers and predicate methods.

1435

* Perform a deep #dup on query cache results so that modifying activerecord attributes does not modify the cached attributes. *Rick Olson*

1436

1437

\# Ensure that has_many :through associations use a count query instead of loading the target when #size is called. Closes #8800 [Pratik Naik]

1438

* Added :unless clause to validations #8003 [monki]. Example:

1439

1440

def using_open_id?

1441

!identity_url.blank?

1442

end

1443

1444

validates_presence_of :identity_url, :if => using_open_id?

1445

validates_presence_of :username, :unless => using_open_id?

1446

validates_presence_of :password, :unless => using_open_id?

1447

1448

* Fix #count on a has_many :through association so that it recognizes the :uniq option. Closes #8801 *Pratik Naik*

* Load database adapters on demand. Eliminates config.connection_adapters and RAILS_CONNECTION_ADAPTERS. Add your lib directory to the $LOAD_PATH and put your custom adapter in lib/active_record/connection_adapters/adaptername_adapter.rb. This way you can provide custom adapters as plugins or gems without modifying Rails. *Jeremy Kemper*

* PostgreSQL: remove DateTime -> Time downcast. Warning: do not enable translate_results for the C bindings if you have timestamps outside Time's domain. *Jeremy Kemper*

1596

1597

* find_or_create_by_* takes a hash so you can create with more attributes than are in the method name. For example, Person.find_or_create_by_name(:name => 'Henry', :comments => 'Hi new user!') is equivalent to Person.find_by_name('Henry') || Person.create(:name => 'Henry', :comments => 'Hi new user!'). #7368*Josh Susser*

1598

1599

* Make sure with_scope takes both :select and :joins into account when setting :readonly. Allows you to save records you retrieve using method_missing on a has_many :through associations. *Michael Koziarski*

* Added fixtures :all as a way of loading all fixtures in the fixture directory at once #7214*Manfred Stienstra*

1628

1629

* Added database connection as a yield parameter to ActiveRecord::Base.transaction so you can manually rollback [David Heinemeier Hansson]. Example:

1630

1631

transaction do |transaction|

1632

david.withdrawal(100)

1633

mary.deposit(100)

1634

transaction.rollback! # rolls back the transaction that was otherwise going to be successful

1635

end

1636

1637

* Made increment_counter/decrement_counter play nicely with optimistic locking, and added a more general update_counters method *Jamis Buck*

1638

1639

* Reworked David's query cache to be available as Model.cache {...}. For the duration of the block no select query should be run more then once. Any inserts/deletes/executes will flush the whole cache however *Tobias Lütke*

1640

Task.cache { Task.find(1); Task.find(1) } # => 1 query

1641

1642

* When dealing with SQLite3, use the table_info pragma helper, so that the bindings can do some translation for when sqlite3 breaks incompatibly between point releases. *Jamis Buck*

* validates_numericality_of uses \A\Z to ensure the entire string matches rather than ^ $ which may match one valid line of a multiline string. #5716*Andreas Schwarz*

1730

1731

* Run validations in the order they were declared. #6657*obrie*

1732

1733

* MySQL: detect when a NOT NULL column without a default value is misreported as default ''. Can't detect for string, text, and binary columns since '' is a legitimate default. #6156*simon@redhillconsulting.com.au, obrie, Jonathan Viney, Jeremy Kemper*

* Removes the ability for eager loaded conditions to be interpolated, since there is no model instance to use as a context for interpolation. #5553*turnip@turnipspatch.com*

1789

1790

* Added timeout option to SQLite3 configurations to deal more gracefully with SQLite3::BusyException, now the connection can instead retry for x seconds to see if the db clears up before throwing that exception #6126*wreese@gmail.com*

* MySQL: introduce Mysql::Result#all_hashes to support further optimization. #5581*Stefan Kaes*

1799

1800

* save! shouldn't validate twice. #6324*maiha, Bob Silva*

1801

1802

* Association collections have an _ids reader method to match the existing writer for collection_select convenience (e.g. employee.task_ids). The writer method skips blank ids so you can safely do @employee.task_ids = params[:tasks] without checking every time for an empty list or blank values. #1887, #5780 *Michael Schuerig*

* Fixed the Ruby/MySQL adapter we ship with Active Record to work with the new authentication handshake that was introduced in MySQL 4.1, along with the other protocol changes made at that time #5723 *jimw@mysql.com*

* Pushing a record onto a has_many :through sets the association's foreign key to the associate's primary key and adds it to the correct association. #5815, #5829 *Josh Susser*

1863

1864

* Add records to has_many :through using <<, push, and concat by creating the association record. Raise if base or associate are new records since both ids are required to create the association. #build raises since you can't associate an unsaved record. #create! takes an attributes hash and creates the associated record and its association in a transaction. *Jeremy Kemper*

* PostgreSQL: autodetected sequences work correctly with multiple schemas. Rely on the schema search_path instead of explicitly qualifying the sequence name with its schema. #5280 *guy.naor@famundo.com*

* Add AssociationCollection#sum since the method_missing invokation has been shadowed by Enumerable#sum.

1985

1986

* Added find_or_initialize_by_X which works like find_or_create_by_X but doesn't save the newly instantiated record. *Sam Stephenson*

1987

1988

* Row locking. Provide a locking clause with the :lock finder option or true for the default "FOR UPDATE". Use the #lock! method to obtain a row lock on a single record (reloads the record with :lock => true). *Shugo Maeda*

1989

# Obtain an exclusive lock on person 1 so we can safely increment visits.

* Refactored ActiveRecord::Base.to_xml to become a delegate for XmlSerializer, which restores sanity to the mega method. This refactoring also reinstates the opinions that type="string" is redundant and ugly and nil-differentiation is not a concern of serialization *David Heinemeier Hansson*

* Removes the ability for eager loaded conditions to be interpolated, since there is no model instance to use as a context for interpolation. #5553 *turnip@turnipspatch.com*

2259

2260

* Added timeout option to SQLite3 configurations to deal more gracefully with SQLite3::BusyException, now the connection can instead retry for x seconds to see if the db clears up before throwing that exception #6126 *wreese@gmail.com*

* Association collections have an _ids reader method to match the existing writer for collection_select convenience (e.g. employee.task_ids). The writer method skips blank ids so you can safely do @employee.task_ids = params[:tasks] without checking every time for an empty list or blank values. #1887, #5780 *Michael Schuerig*

* Fixed the Ruby/MySQL adapter we ship with Active Record to work with the new authentication handshake that was introduced in MySQL 4.1, along with the other protocol changes made at that time #5723 *jimw@mysql.com*

* Pushing a record onto a has_many :through sets the association's foreign key to the associate's primary key and adds it to the correct association. #5815, #5829 *Josh Susser*

2323

2324

* Add records to has_many :through using <<, push, and concat by creating the association record. Raise if base or associate are new records since both ids are required to create the association. #build raises since you can't associate an unsaved record. #create! takes an attributes hash and creates the associated record and its association in a transaction. *Jeremy Kemper*

* PostgreSQL: autodetected sequences work correctly with multiple schemas. Rely on the schema search_path instead of explicitly qualifying the sequence name with its schema. #5280 *guy.naor@famundo.com*

* Add AssociationCollection#sum since the method_missing invokation has been shadowed by Enumerable#sum.

2437

2438

* Added find_or_initialize_by_X which works like find_or_create_by_X but doesn't save the newly instantiated record. *Sam Stephenson*

2439

2440

* Row locking. Provide a locking clause with the :lock finder option or true for the default "FOR UPDATE". Use the #lock! method to obtain a row lock on a single record (reloads the record with :lock => true). *Shugo Maeda*

2441

# Obtain an exclusive lock on person 1 so we can safely increment visits.

* Refactored ActiveRecord::Base.to_xml to become a delegate for XmlSerializer, which restores sanity to the mega method. This refactoring also reinstates the opinions that type="string" is redundant and ugly and nil-differentiation is not a concern of serialization *David Heinemeier Hansson*

* Any additional join references get a numerical suffix like '_2', '_3', etc.

2902

2903

* Fixed eager loading problems with single-table inheritance #3580 [Rick Olson]. Post.find(:all, :include => :special_comments) now returns all posts, and any special comments that the posts may have. And made STI work with has_many :through and polymorphic belongs_to.

2904

2905

* Added cascading eager loading that allows for queries like Author.find(:all, :include=> { :posts=> :comments }), which will fetch all authors, their posts, and the comments belonging to those posts in a single query (using LEFT OUTER JOIN) #3913 [anna@wota.jp]. Examples:

* Added Sybase database adapter that relies on the Sybase Open Client bindings (see http://raa.ruby-lang.org/project/sybase-ctlib) #3765 [John Sheets]. It's almost completely Active Record compliant (including migrations), but has the following caveats: