Delete record from console in Hanami

349 Views Asked by At

In Rails you can do:

rails c
record = Record.where(name: 'Test Record').first
record.destroy

How can you do the same in Hanami? I've been reading through the docs but I'm struggling to see how to do console commands like Rails to interact with the database objects.

2

There are 2 best solutions below

0
On BEST ANSWER

You can do

$ hanami c
UserRepository.new.users.where(name: "Test Record").delete
3
On

When a class inherits from Hanami::Repository

delete(id) – Delete the record corresponding to the given id

in Hanami use delete instead of destroy