luckyframework / luckyframework/avram

Allow specifying primary key on has_many and has_one relationships

Open
#490 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Right now we assume that the connected table always points at the table's primary key. This makes sense for the VAST majority of cases but this causes issues when we want to add support for tables without primary keys and it's also possible to do joins on non-primary key columns. This is a bad example, but here is what it would look like:

```crystal
class User
table do
column name : String
has_many name_infos : NameInfo, foreign_key: "user_name", primary_key: "name"
end
end
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing how has_many and has_one relationships resolve their foreign keys. Confirm the expected behavior for explicit primary_key and foreign_key options, including tables without primary keys, then add focused coverage for the demonstrated Crystal relationship syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.