Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository::find doesn't seem to work with composite keys #432

Open
graywolf opened this issue Aug 9, 2017 · 7 comments
Open

Repository::find doesn't seem to work with composite keys #432

graywolf opened this issue Aug 9, 2017 · 7 comments

Comments

@graywolf
Copy link

graywolf commented Aug 9, 2017

Assuming I have table containing composite primary key

primary_key [:name, :version]

column :name, String
column :version, String

I didn't find a way to retrieve such record using Repository.new.find. Tried this

repository.find({ name: n, version: v })

but got

Hanami::Model::Error: ROM:Relation[Statuses]#by_pk arity is 2 (1 args given)

Is there a way to retrieve it? Don't seem like it based on source code (afaict)... So how am I supposed to use composite keys? Thanks :)

@mereghost mereghost added the bug label Aug 30, 2017
@mereghost
Copy link
Member

ROM can deal with composite keys but it seems that hanami-model can't deal with them right now.

@graywolf
Copy link
Author

graywolf commented Aug 31, 2017

If ROM can deal with it, would changing

root.by_pk(id).as(:entity).one

to

root.by_pk(*id).as(:entity).one

suffice (source)? It would than be called

repository.find([name, version])

or

repository.find(name, version)

I would prefer the first one imho. But supporting syntax like

repository.find({ name: n, version: v })

would be best but no longer one-line change; I'm sure it can be implemented however I have no idea where to start.

@AlfonsoUceda
Copy link
Contributor

@mereghost what do you think? can you implement this?

@AlfonsoUceda AlfonsoUceda self-assigned this Oct 12, 2017
@AlfonsoUceda
Copy link
Contributor

Working on this.

@jodosha jodosha removed the bug label Nov 27, 2017
@AlfonsoUceda AlfonsoUceda removed their assignment Feb 17, 2018
@MichalJaneda
Copy link

@AlfonsoUceda are you still working on it? If not, may I try to take this over?

@adam12
Copy link
Member

adam12 commented Jan 4, 2021

@MichalJaneda they removed their assignment so you're probably safe to work on it,

@AlfonsoUceda
Copy link
Contributor

Hey @MichalJaneda yes you can work on that, but better confirm with @jodosha if it worths it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants