Merge pull request #49179 from Shopify/cpk-release-notes
[ci skip] Add composite primary key release note
This commit is contained in:
commit
9dc2288d64
@ -150,7 +150,26 @@ and reporting of the bulk enqueuing process.
|
||||
|
||||
### Composite primary keys
|
||||
|
||||
TODO: Add description
|
||||
Composite primary keys are now supported at both the database and application level. Rails is able to derive these keys directly from the schema. This feature is particularly beneficial for many-to-many relationships and other complex data models where a single column is insufficient to uniquely identify a record.
|
||||
|
||||
The SQL generated by query methods in Active Record (e.g. `#reload`, `#update`, `#delete`) will contain all parts of the composite primary key. Methods like `#first` and `#last` will use the full composite primary key in the `ORDER BY` statements.
|
||||
|
||||
The `query_constraints` macro can be used as a "virtual primary key" to achieve the same behavior without modifying the database schema.
|
||||
Example:
|
||||
```ruby
|
||||
class TravelRoute < ActiveRecord::Base
|
||||
query_constraints :origin, :destination
|
||||
end
|
||||
```
|
||||
|
||||
Similarly, associations accept a `query_constraints:` option. This option serves as a composite foreign key, configuring the list of columns used for accessing the associated record.
|
||||
|
||||
Example:
|
||||
```ruby
|
||||
class TravelRouteReview < ActiveRecord::Base
|
||||
belongs_to :travel_route, query_constraints: [:travel_route_origin, :travel_route_destination]
|
||||
end
|
||||
```
|
||||
|
||||
### Introduce adapter for `Trilogy`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user