jesjos / jesjos/active_record_upsert
Rails - upsert no unique index found
- Dominant language
- Ruby
- Stars
- 207
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
This is my migration file.
```
def change
add_index :book_owners, [:book_id, :book_detail_id], unique: true, where: 'book_id IS NOT NULL and book_detail_id IS NOT NULL'
end
```
This is my code.
```
BookOwners.upsert({
book_id: 123,
book_detail_id: 234,
...
}, unique_by: { columns: [:book_id, :book_detail_id] })
```
But I am getting this error.
`No unique index found for {:columns=>[:book_id, :book_detail_id]}`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the reported migration and BookOwners.upsert call, then trace how unique_by columns are matched against the unique index. Confirm whether the partial unique index is recognized and capture the expected behavior or a clear compatibility limitation in a regression test or issue resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100