Add AR::Base.to_param for convenient "pretty" URLs derived from a model's attribute or method.
class methods moved to already defined class<<self block
Merge pull request #12890 from akshay-vishnoi/refactor

class methods moved to already defined class<<self block
Merge pull request #12891 from javan/to-param

Add AR::Base.to_param for convenient "pretty" URLs derived from a model's attribute or method
Used Yield instead of block.call
Merge pull request #12889 from kuldeepaggarwal/speed_ups

Used Yield instead of block.call
Allow AR:B.where(belongs_to_assoc: val) to accept non AR:B values

When referring to a belongs_to association in a query, nil,
Arrays, or AR:Relations values would cause the PredicateBuilder
to skip over the part of the PredicateBuilder that expanded
the association name into the foreign key.

For example:

    Post.where(author: nil)

This should return posts where the author is not set, but instead
it generates an invalid SQL statement using the association name.

    # Invalid SQL generated previousl
    SELECT "posts".* FROM "posts" WHERE "posts"."author" IS NULL

This fix removes the requirement that the association value is an
ActiveRecord::Base object when converting the association name to its
respective foreign key.

    # New valid SQL returning the expected result.
    SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL

This also allows values that are arrays or AR:Relations to be handled
properly just like they would be if you used author_id as the column.

    Post.where(author: [Author.find(1), Author.find(2)])
    SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IN (1, 2)

    Post.where(author: Author.where(id: [1,2]))
    SELECT "posts".* FROM "posts"  WHERE "posts"."author_id" IN (SELECT
      "authors"."id" FROM "authors"  WHERE "authors"."id" IN (1, 2))