Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix replacing foreign key for a CPK association by id attribute #47924

Merged

Commits on Apr 12, 2023

  1. Fix replacing foreign key for a CPK association by id attribute

    Given a model associated with a composite primary key by `id` attribute,
    for example:
    ```ruby
    Order.primary_key = [:shop_id, :id]
    OrderAgreement.primary_key = :id
    
    OrderAgreement.belongs_to :order, primary_key: :id
    ```
    
    Assigning `order` to an `OrderAgreement` object will replace the
    `order_id` foreign key:
    
    ```ruby
    order = Order.last # => #<Order id: 1, shop_id: 2>
    
    order_agreement = OrderAgreement.new(order: order).save
    order_agreement.order_id # => 1
    ```
    nvasilevski committed Apr 12, 2023
    Configuration menu
    Copy the full SHA
    c0da60f View commit details
    Browse the repository at this point in the history