diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-23 11:18:54 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-23 11:18:54 -0300 |
commit | 069c03b2d1909b331dd8aaa3e07aaea989a2d6e6 (patch) | |
tree | 91ddc9e70524eeb8591af1903a4ff486ec645f38 /guides/source | |
parent | 49389104456526e35d9d65d787cd904fa5a55d85 (diff) | |
parent | 6576f7354e50afb79881aaf3a6f50f4e81dfab70 (diff) | |
download | rails-069c03b2d1909b331dd8aaa3e07aaea989a2d6e6.tar.gz rails-069c03b2d1909b331dd8aaa3e07aaea989a2d6e6.tar.bz2 rails-069c03b2d1909b331dd8aaa3e07aaea989a2d6e6.zip |
Merge pull request #18937 from simi/optional-belongs-to
Require `belongs_to` by default.
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/association_basics.md | 5 | ||||
-rw-r--r-- | guides/source/configuring.md | 2 |
2 files changed, 7 insertions, 0 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index cd715aba1f..0079049d44 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -833,6 +833,7 @@ The `belongs_to` association supports these options: * `:polymorphic` * `:touch` * `:validate` +* `:optional` ##### `:autosave` @@ -956,6 +957,10 @@ end If you set the `:validate` option to `true`, then associated objects will be validated whenever you save this object. By default, this is `false`: associated objects will not be validated when this object is saved. +##### `:optional` + +If you set the `:optional` option to `true`, then associated object will be validated for presence. By default, this is `false`: associated objects will be validated for presence. + #### Scopes for `belongs_to` There may be times when you wish to customize the query used by `belongs_to`. Such customizations can be achieved via a scope block. For example: diff --git a/guides/source/configuring.md b/guides/source/configuring.md index ab1cc9306f..4fc1301e06 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -300,6 +300,8 @@ All these configuration options are delegated to the `I18n` library. `config/environments/production.rb` which is generated by Rails. The default value is true if this configuration is not set. +* `config.active_record.belongs_to_required_by_default` is a boolean value and controls whether `belongs_to` association is required by default. + The MySQL adapter adds one additional configuration option: * `ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans` controls whether Active Record will consider all `tinyint(1)` columns in a MySQL database to be booleans and is true by default. |