Skip to content

Conversation

@niciliketo
Copy link
Contributor

What this does

Explicitly specify the inverse_of messages relationship because the foreign_key attribute is set since v.1.3.0

This seems to be required by active record as described in the rails guides page on associations

Due to the :foreign_key option, Active Record will not automatically recognize the bi-directional association, which can lead to several issues:
...
By including the :inverse_of option in the has_many association declaration, Active Record will recognize the bi-directional association and behave as described in the initial examples above.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Related issues

Explicitly specify the inverse_of messages relationship because the foreign_key attribute is set.

Add spec to confirm the change.

This seems to be required by active record as described here:
https://guides.rubyonrails.org/association_basics.html#bi-directional-associations

> Due to the :foreign_key option, Active Record will not automatically recognize the bi-directional association, which can lead to several issues:
> ...
> By including the :inverse_of option in the has_many association declaration, Active Record will recognize the bi-directional association and behave as described in the initial examples above.
@codecov
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.87%. Comparing base (ab97f12) to head (009ff12).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #230      +/-   ##
==========================================
- Coverage   89.92%   89.87%   -0.06%     
==========================================
  Files          75       75              
  Lines        2800     2776      -24     
  Branches      549      543       -6     
==========================================
- Hits         2518     2495      -23     
+ Misses        282      281       -1     

☔ 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.

Copy link
Owner

@crmne crmne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @niciliketo

@crmne crmne merged commit f312431 into crmne:main Jun 11, 2025
14 checks passed
@crmne crmne linked an issue Jun 11, 2025 that may be closed by this pull request
3 tasks
parruda pushed a commit to parruda/ruby_llm that referenced this pull request Nov 18, 2025
## What this does

Explicitly specify the `inverse_of` messages relationship because the
`foreign_key` attribute is set since
[v.1.3.0](crmne/ruby_llm@1.2.0...1.3.0)

This seems to be required by active record as described in the [rails
guides page on
associations](https://guides.rubyonrails.org/association_basics.html#bi-directional-associations)

> Due to the :foreign_key option, Active Record will not automatically
recognize the bi-directional association, which can lead to several
issues:
> ...
> By including the :inverse_of option in the has_many association
declaration, Active Record will recognize the bi-directional association
and behave as described in the initial examples above.

## Type of change

- [x] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation
- [ ] Performance improvement

## Scope check

- [x] I read the [Contributing
Guide](https://github.com/crmne/ruby_llm/blob/main/CONTRIBUTING.md)
- [x] This aligns with RubyLLM's focus on **LLM communication**
- [x] This isn't application-specific logic that belongs in user code
- [x] This benefits most users, not just my specific use case

## Quality check

- [x] I ran `overcommit --install` and all hooks pass
- [x] I tested my changes thoroughly
- [x] I updated documentation if needed
- [x] I didn't modify auto-generated files manually (`models.json`,
`aliases.json`)

## API changes

- [ ] Breaking change
- [ ] New public methods/classes
- [ ] Changed method signatures
- [x] No API changes

## Related issues

<!-- Link issues: "Fixes crmne#123" or "Related to crmne#123" -->

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.

[BUG] Addition of foreign_key to acts_as_message affects active record relation

2 participants