aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #29494 from kamipo/prevent_extra_scope_constructionRafael França2017-06-193-3/+5
|\ | | | | Prevent extra `scope` construction in `find_target`
| * Prevent extra `scope` construction in `find_target`Ryuta Kamizono2017-06-183-3/+5
| | | | | | | | Because constructing `scope` is a little expensive.
* | Merge pull request #29486 from kirs/fixtures-arelRafael França2017-06-191-4/+11
|\ \ | |/ |/| Refactor #insert_fixtures to use Arel
| * Refactor #insert_fixtures to use ArelKir Shatrov2017-06-191-4/+11
| |
* | Merge pull request #29455 from kirs/remove-column-with-fk-mysqlGuillermo Iguaran2017-06-161-0/+7
|\ \ | | | | | | Remove FK together with column in MySQL
| * | Remove FK together with column in MySQLKir Shatrov2017-06-161-0/+7
| | | | | | | | | | | | | | | | | | | | | Unlike with other databses, MySQL doesn't let you remove the column if there's a FK on this column. For better developer experience we want to remove the FK together with the column.
* | | Merge pull request #29392 from alexcameron89/unpersisted_create_associationMatthew Draper2017-06-171-0/+4
|\ \ \ | | | | | | | | Raise on create for singular association when parent is unpersisted
| * | | Raise on create for singular association when parent is unpersistedAlex Kitchens2017-06-081-0/+4
| |/ / | | | | | | | | | | | | | | | A collection association will raise on `#create_association` when the parent is unpersisted. A singular association should do the same. This addresses issue #29219.
* | | Merge pull request #29431 from kamipo/fix_create_table_with_query_from_relationMatthew Draper2017-06-171-1/+6
|\ \ \ | | | | | | | | Fix `create_table` with query from relation
| * | | Fix `create_table` with query from relationRyuta Kamizono2017-06-131-1/+6
| | | | | | | | | | | | | | | | | | | | If a relation has binds, `connection.to_sql(relation)` without binds will generate invalid SQL. It should use `relation.to_sql` in that case.
* | | | Merge pull request #29461 from dnl/unscope_where_orMatthew Draper2017-06-171-1/+1
|\ \ \ \ | |_|_|/ |/| | | Don't require 'unscope' to be the same on both sides of an 'or' relation
| * | | Don't require 'unscope' to be the same for both sides of a 'or' relation.Dan Sherson2017-06-151-1/+1
| | | |
* | | | Merge pull request #29464 from eugeneius/raw_write_attributeRafael França2017-06-151-15/+6
|\ \ \ \ | | | | | | | | | | Don't map id to primary key in raw_write_attribute
| * | | | Don't map id to primary key in raw_write_attributeEugene Kenny2017-06-151-15/+6
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `raw_write_attribute` method is used to update a record's attributes to reflect the new state of the database in `update_columns`. The hash provided to `update_columns` is turned into an UPDATE query directly, which means passing an `id` key results in an update to the `id` column, even if the model uses a different attribute as its primary key. When updating the record, we don't want to apply the `id` column change to the primary key attribute, since that's not what happened in the query. Without the code to handle this case, `write_attribute_with_type_cast` no longer contains any logic shared between `raw_write_attribute` and `write_attribute`, so we can inline the code into those two methods.
* | | | Fix `dump_schema_information` with empty versionsRyuta Kamizono2017-06-151-1/+1
| | | | | | | | | | | | | | | | Fixes #29460.
* | | | Remove deprecated option from docs [ci skip] (#29459)Vipul A M2017-06-151-6/+6
|/ / /
* | | Prevent extra `sync_with_transaction_state`Ryuta Kamizono2017-06-151-5/+2
| | | | | | | | | | | | | | | `sync_with_transaction_state` in `to_key` is unneeded because `id` also does.
* | | Merge pull request #29378 from kamipo/avoid_overwriting_id_attribute_methodsRafael França2017-06-141-7/+3
|\ \ \ | |/ / |/| | Avoid overwriting the methods of `AttributeMethods::PrimaryKey`
| * | Avoid overwriting the methods of `AttributeMethods::PrimaryKey`Ryuta Kamizono2017-06-071-7/+3
| |/ | | | | | | | | | | | | | | | | Currently the methods of `AttributeMethods::PrimaryKey` are overwritten by `define_attribute_methods`. It will be broken if a table that customized primary key has non primary key id column. It should not be overwritten if a table has any primary key. Fixes #29350.
* / Remove `null_allowed` option from doc [ci skip]yuuji.yaginuma2017-06-101-2/+1
|/ | | | This option was added in b9fa354. But it does not seem to work.
* [ci skip] UNIQUE constraint affects not only INSERT but also UPDATERyuta Kamizono2017-06-061-1/+1
|
* Don't mark the schema loaded until it's really finishedMatthew Draper2017-06-051-3/+5
| | | | | load_schema! is overridden by attribute modules, so we need to wait until it has returned.
* Merge pull request #29294 from gsamokovarov/attributes-defaultKasper Timm Hansen2017-06-045-21/+10
|\ | | | | Introduce mattr_accessor default option
| * Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-035-21/+10
| |
* | [ci skip] Add missing `be`Prathamesh Sonpatki2017-06-031-1/+1
|/
* Merge pull request #29135 from ↵Eileen M. Uchitelle2017-06-021-0/+19
|\ | | | | | | | | Nerian/document_support_for_composite_primary_keys Document support for composite primary keys
| * Document support for composite primary keysNerian2017-05-181-0/+19
| |
* | Merge pull request #29282 from ↵Eileen M. Uchitelle2017-06-022-8/+13
|\ \ | | | | | | | | | | | | kamipo/prevent_making_bind_param_if_casted_value_is_nil Prevent making bind param if casted value is nil
| * | Prevent making bind param if casted value is nilRyuta Kamizono2017-05-312-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | If casted value is nil, generated SQL should be `IS NULL`. But currently it is generated as `= NULL`. To prevent this behavior, avoid making bind param if casted value is nil. Fixes #28945.
* | | Merge pull request #29220 from kamipo/consolidate_database_specific_json_typesMatthew Draper2017-06-017-45/+35
|\ \ \ | | | | | | | | Consolidate database specific JSON types to `Type::Json`
| * | | Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-307-45/+35
| | | |
* | | | Merge pull request #29293 from kamipo/fix_sti_with_default_scopeMatthew Draper2017-06-011-1/+5
|\ \ \ \ | | | | | | | | | | Fix `default_scoped` with defined `default_scope` on STI model
| * | | | Fix `default_scoped` with defined `default_scope` on STI modelRyuta Kamizono2017-05-311-1/+5
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | This regression is caused by d1249c1. If STI model is defined `default_scope`, `base_rel` is not respected. I fixed to merge `base_rel` in that case.
* | | | Should use `quote` for a string literalRyuta Kamizono2017-06-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow up of #29077. Before: ```sql SELECT sql FROM sqlite_master WHERE tbl_name NOT IN ("foo") ORDER BY tbl_name, type DESC, name ``` After: ```sql SELECT sql FROM sqlite_master WHERE tbl_name NOT IN ('foo') ORDER BY tbl_name, type DESC, name ``` > If a keyword in double quotes (ex: "key" or "glob") is used in a context where it cannot be resolved to an identifier but where a string literal is allowed, then the token is understood to be a string literal instead of an identifier. http://www.sqlite.org/lang_keywords.html
* | | | Add missing `delegate :extending, to: :all`Ryuta Kamizono2017-06-011-1/+1
|/ / /
* | | Merge pull request #29261 from ↵Matthew Draper2017-05-317-29/+39
|\ \ \ | | | | | | | | | | | | | | | | kamipo/dont_expose_methods_and_attrs_for_internal_usage Don't expose methods and attrs for internal usage
| * | | Don't expose methods and attrs for internal usageRyuta Kamizono2017-05-307-29/+39
| |/ /
* / / Support PostgreSQL 10 `pg_sequence`Yasuo Honda2017-05-301-1/+9
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | Another fix for #28780 based on discussions at #28789 - In PostgreSQL 10 each sequence does not know its `min_value`. A new system catalog `pg_sequence` shows it as `seqmin`. Refer https://github.com/postgres/postgres/commit/1753b1b027035029c2a2a1649065762fafbf63f3 - `setval` 3rd argument needs to set to `false` only when the table has no rows to avoid `nextval(<sequence_name>)` returns `2` where `1` is expected. - `min_value` is only necessary when the table has no rows. It used to be necessary since the 3rd argument of `setval` is always `false`.
* | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-307-32/+33
|\ \ | | | | | | | | | Fix association with extension issues
| * | Extract `default_extensions` to avoid `klass.all`Ryuta Kamizono2017-05-302-1/+9
| | | | | | | | | | | | | | | As @matthewd's suggestion, if `klass` has no default scope, it will more faster.
| * | Refactor `default_scoped` to avoid creating extra relation and mergingRyuta Kamizono2017-05-281-7/+2
| | |
| * | Cache the association proxy objectRyuta Kamizono2017-05-282-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some third party modules expects that association returns same proxy object each time (e.g. for stubbing collection methods: https://github.com/rspec/rspec-rails/issues/1817). So I decided that cache the proxy object and reset scope in the proxy object each time. Related context: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
| * | Fix association with extension issuesRyuta Kamizono2017-05-285-24/+18
| | | | | | | | | | | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* | | Merge pull request #29273 from ↵Rafael França2017-05-293-15/+4
|\ \ \ | | | | | | | | | | | | | | | | kamipo/deserialize_raw_value_from_database_for_json Deserialize a raw value from the database in `changed_in_place?` for `AbstractJson`
| * | | Deserialize a raw value from the database in `changed_in_place?` for ↵Ryuta Kamizono2017-05-303-15/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `AbstractJson` Structured type values sometimes caused representation problems (keys sort order, spaces, etc). A raw value from the database should be deserialized (normalized) to prevent the problems.
* | | | Fix UUID column with `null: true` and `default: nil`Ryuta Kamizono2017-05-301-1/+1
|/ / / | | | | | | | | | | | | | | | | | | `quote_default_expression` can be passed nil value when `null: true` and `default: nil`. This addressed in that case. Fixes #29222.
* | | Merge pull request #29248 from yawboakye/rename-should-rename-table-pkeyGuillermo Iguaran2017-05-291-4/+5
|\ \ \ | | | | | | | | `rename_table` should rename primary key index name
| * | | `rename_table` renames primary key index nameYaw Boakye2017-05-291-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Formerly, `rename_table` only renamed primary key index name if the column's data type was sequential (serial, etc in PostgreSQL). The problem with that is tables whose primary keys had other data types (e.g. UUID) maintained the old primary key name. So for example, if the `cats` table has a UUID primary key, and the table is renamed to `felines`, the primary key index will still be called `cats_pkey` instead of `felines_pkey`. This PR corrects it.
* | | | Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-2916-72/+31
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* | | Merge pull request #29208 from ↵Guillermo Iguaran2017-05-281-1/+1
|\ \ \ | | | | | | | | | | | | | | | | kamipo/default_env_fall_back_to_default_env_when_rails_env_or_rack_env_is_empty_string `DEFAULT_ENV` falls back to `default_env` when `RAILS_ENV` or `RACK_ENV` is an empty string