Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanety/active_hash-associations-definitions
https://github.com/kanety/active_hash-associations-definitions
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kanety/active_hash-associations-definitions
- Owner: kanety
- License: mit
- Created: 2021-07-17T01:14:16.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-18T10:36:39.000Z (about 3 years ago)
- Last Synced: 2024-12-25T04:04:42.371Z (23 days ago)
- Language: Ruby
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ActiveHash::Associations::Definitions
Keep association definitions for [active_hash](https://github.com/zilkey/active_hash).
## Dependencies
* ruby 2.4+
* activesupport 5.0+
* active_hash 3.0+## Installation
Add this line to your application's Gemfile:
```ruby
gem 'active_hash-associations-definitions'
```Then execute:
$ bundle
## Usage
Inlcude additional `ActiveHash::Associations::Definitions` and use `has_many` and `belongs_to` as usual.
For example:```ruby
class Item < ActiveHash::Base
include ActiveHash::Associations
include ActiveHash::Associations::Definitionsfield :parent_id
belongs_to :parent, foreign_key: :parent_id, class_name: self.name
has_many :children, foreign_key: :parent_id, class_name: self.name
end
```You can access association definitions as follows:
```ruby
Item.association_definition(:parent)
#=> #:parent_id, :class_name=>"Item"}>
Item.association_definition(:children)
#=> #:parent_id, :class_name=>"Item"}>
```## Contributing
Bug reports and pull requests are welcome at https://github.com/kanety/active_hash-associations-definitions.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).