luckyframework / luckyframework/avram
Extract module for overriding `find` with Slugify
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
You can find record with Avram's built-in query methods.
```crystal
ArticleQuery.new.slug("avram-is-a-great-orm").first
```
Or if you want to add a shortcut you can do something like this:
```crystal
class ArticleQuery < Article::BaseQuery
def find(slug_or_id : String | Int64) : Article
if slug_or_id.is_a?(Int64)
previous_def(slug_or_id)
else
slug(slug_or_id).first
end
end
end
# Find by slug
ArticleQuery.find("avram-is-a-great-orm")
# Find by id
ArticleQuery.find(1_i64)
# Can be scoped like any other query
ArticleQuery.new.account_id(account.id).find("avram-is-a-great-orm")
```
So you can just `include AvramSlugify::Finder` in your Query class
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 with Avram's query methods and the ArticleQuery example in the issue, then inspect how Query classes expose find and slug. Extract the shown behavior behind AvramSlugify::Finder and verify that including it supports both slug and Int64 lookups, including scoped queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100