rails/activerecord/test/models/cpk.rb
Nikita Vasilevsky fb127c0d42 Define ActiveRecord::Base#id API for composite primary key models
Given a model with a composite primary key:
```ruby
class Order < ActiveRecord::Base
  self.primary_key = [:shop_id, :id]
end
```

`ActiveRecord::Base#id` method will return an array of values for every
column of the primary key.

```ruby
order = Order.create!(shop_id: 1, id: 2)
order.id # => [1, 2]
```

The `id` column is accessible through the `read_attribute` method:

```ruby
order.read_attribute(:id) # => 2
```
2023-03-10 14:42:57 +00:00

5 lines
88 B
Ruby

# frozen_string_literal: true
require_relative "cpk/book"
require_relative "cpk/order"