luckyframework / luckyframework/avram
Allow assigning n:m relationships
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Given the example from the guides:
```crystal
class Tagging < BaseModel
table :taggings do
belongs_to tag : Tag
belongs_to post : Post
end
end
class Tag < BaseModel
table :tags do
column name : String
has_many taggings : Tagging
has_many posts : Post, through: :taggings
end
end
class Post < BaseModel
table :posts do
column title : String
has_many taggings : Tagging
has_many tags : Tag, through: :taggings
end
end
```
it would be great if there was an easy way to assign tags to posts.
For example in ActiveRecord the same example would give you a `tag_ids=` method on the `Post` model. When calling `post.tag_ids = [1, 3, 5]` ActiveRecord will transparently create and / or delete `Tagging` records to make sure the post is associated with the tags 1, 3 and 5, and only with them. This makes it easy to create HTML forms to edit relationships (either via checkboxes or multiple selects).
I am not 100% sure how this could look in LuckyRecord. Of course it would be super nice to be able to say `fillable tag_ids` in your form class and have everything else work automatically.
On the other hand: `fillable` is currently reserved for fields whose values get saved to the actual database table that belongs to the underlying model. So in some ways this would be closer to a `virtual` field :man_shrugging:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Tagging, Tag, and Post relationship example in the issue, then inspect how LuckyRecord currently handles has_many-through associations and fillable fields. The desired result is a tag_ids assignment that creates or deletes Tagging records so a post has exactly the selected tags; no files or tests are named, so the relevant entry points must first be located.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100