Skip to content

Updated acts_as_* helpers to use canonical 'rails-style' foreign keys #151

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

Merged
merged 2 commits into from
May 6, 2025

Conversation

timaro
Copy link
Contributor

@timaro timaro commented May 4, 2025

This updates the acts_as_message, acts_as_chat and acts_as_tool class methods to use Rails-style foreign keys whenever custom class names are used as options. For example:

class FooMessage < ActiveRecord::Base
  acts_as_message chat_class: 'FooChat', tool_call_class: 'FooToolCall'
end

will now set the foreign key on the belongs_to :chat association to be foo_chat_id, instead of chat_id, and will set the foreign key on belongs_to :parent_tool_call association to foo_tool_call_id instead of just tool_call_id.

This is consistent with Rails' naming conventions for class names and foreign keys. Changes are backwards-compatible with existing code/behavior, and don't require a major or minor version bump.

Updated test cases to ensure that the associations are working, but didn't re-record VCR tests, since I don't have an OpenAPI key.

Closes #150

@crmne crmne merged commit 860dbfd into crmne:main May 6, 2025
5 checks passed
Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.65%. Comparing base (2e0e4dc) to head (4796557).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #151      +/-   ##
==========================================
+ Coverage   93.57%   93.65%   +0.07%     
==========================================
  Files          87       87              
  Lines        3160     3199      +39     
  Branches      421      422       +1     
==========================================
+ Hits         2957     2996      +39     
  Misses        203      203              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timaro timaro deleted the fix_foreign_keys branch May 6, 2025 16:02
crmne added a commit that referenced this pull request May 6, 2025
…#151)

This updates the acts_as_message, acts_as_chat and acts_as_tool class
methods to use Rails-style foreign keys whenever custom class names are
used as options. For example:

```
class FooMessage < ActiveRecord::Base
  acts_as_message chat_class: 'FooChat', tool_call_class: 'FooToolCall'
end
```

will now set the foreign key on the `belongs_to :chat` association to be
`foo_chat_id`, instead of `chat_id`, and will set the foreign key on
`belongs_to :parent_tool_call` association to `foo_tool_call_id` instead
of just `tool_call_id`.

This is consistent with Rails' naming conventions for class names and
foreign keys. Changes are backwards-compatible with existing
code/behavior, and don't require a major or minor version bump.

Updated test cases to ensure that the associations are working, but
didn't re-record VCR tests, since I don't have an OpenAPI key.

Closes #150

Co-authored-by: Carmine Paolino <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveRecord::ActsAs foreign keys are broken when class names change
2 participants