These fixtures were added in 9a4e183fe9f81365f7815c391512b3d46622d8c8 to
test the behavior of `connection.truncate`, but then the relevant tests
were extracted to `AdapterTestWithoutTransaction` in
fdac932707fb16b7d074b1d0bc7c255157d72675.
`ActiveRecordMessagePackTest` does not use any fixtures, but fixtures
that were previously loaded without preserving referential integrity can
affect query results. For example, if previous tests load `:comments`
fixtures but not `:posts` fixtures, there will be `Comment` records in
the database with `post_id = 1` but no corresponding `Post` record.
Then, when a `Post` is created in `ActiveRecordMessagePackTest`, its
`comments` association will accidentally include those prior `Comment`
records.
This commit loads ambient fixtures for the relevant models in
`ActiveRecordMessagePackTest` to prevent such accidental results.
Fixes#49143.
Previously, a composite primary key model would need to specify
either a `primary_key` or `query_constraints` option on its associations.
Without it, a `CompositePrimaryKeyMismatchError` would be raised.
Most of the time, the composite primary key includes the `:id` column,
and associations already expect that `:id` is being used as the
primary key for the association (and have a corresponding foreign_key
column set on the associated model).
Rather than requiring users to define `primary_key: :id` throughout
an application with composite primary key associations, we can infer
that the `:id` column should be used. Users can still override this
behaviour by specifying a `primary_key:` or `query_constraints:` on
the association.
Note that, if the composite primary key for a model does _not_ include
`:id`, Rails won't infer the primary key for any related associations,
and users must still specify `query_constraints` or `primary_key`.
Prior to this change, you'd need to do the following to set up
associations for composite primary key models:
```ruby
class Order
self.primary_key = [:shop_id, :id]
has_many :order_agreements, primary_key :id
end
class OrderAgreement
belongs_to :order, primary_key: :id
end
```
After this change, the `primary_key` option no longer needs to be
specified:
```ruby
class Order
self.primary_key = [:shop_id, :id]
has_many :order_agreements
end
class OrderAgreement
belongs_to :order
end
```
- Action Controller Overview: Add example of how a cpk record can be
found using a show action.
- Action View Form Helpers: Add example of what a form updating a cpk
record looks like.
- Action View Helpers: Add examples for url_for and link_to cpk record
urls.
Since 6983a89c726243fb38fe28cff49cba3a5f63ba6f `require_dependency` is
obsolete since Rails stopped supporting classic mode.
It is only used by engines that need to support classic mode as well.
We can safely remove internal usage of `require_dependency`.
It was only used in the ActionMailer::Preview which is using just
`require` anyway.
By default `simple_format` method returns the text wrapped with `<p>`. But if we explicitly specify
the `wrapper_tag: nil` in the options, it returns the text wrapped with `<></>` tag.
Before:
```ruby
simple_format("Hello World", {}, { wrapper_tag: nil })
# <>Hello World</>
```
After:
```ruby
simple_format("Hello World", {}, { wrapper_tag: nil })
# <p>Hello World</p>
```
Co-authored-by: Junichi Ito <jit@sonicgarden.jp>
Follow-up to #47420.
Whereas the original behavior (`on: :create`) is invoked only once
before a record is persisted, the new behavior (`on: :initialize`) is
invoked not only new record but also persisted records.
It should be invoked only once for new record consistently.