# Updating Hanami Entity

**URL:** <https://discourse.hanakai.org/t/updating-hanami-entity/444>\
**Category:** questions\
**Created:** [May 5, 2018, 12:26am UTC](https://discourse.hanakai.org/t/updating-hanami-entity/444 "2018-05-05T00:26:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hectorsq](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/hectorsq/32/280_2.png) [@hectorsq](https://discourse.hanakai.org/u/hectorsq)\
**Post date:** [May 5, 2018, 12:26am UTC](https://discourse.hanakai.org/t/updating-hanami-entity/444/1 "2018-05-05T00:26:19Z")

</div>

I just noticed that it is not possible to modify attributes on entities. Using hanami console with the bookshelf project I get the following

```ruby
$ hanami c
2.5.1 :001 > repository = BookRepository.new
 => #<BookRepository relations=[:books]>
2.5.1 :002 > book = repository.create(title: 'TDD', author: 'Kent Beck')
 => #<Book:0x00007fb8e3bb7d00 @attributes={:id=>2, :title=>"TDD", :author=>"Kent Beck", :created_at=>2018-05-05 00:06:54 UTC, :updated_at=>2018-05-05 00:06:54 UTC}>
2.5.1 :003 > book.title
 => "TDD"
2.5.1 :004 > book.title = 'XP'
...
`method_missing'
NoMethodError (undefined method `title=' for #<Book:0x00007fb8e3bb7d00>)
2.5.1 :005 >

```

Coming from a Rails background this surprised me a lot.  
Is this by design?  
Am I missing something?

If this is how hanami works, then which are the recommended steps to get an entity from database, do some processing and save the changes to database?

I was thinking in the following…

```ruby
book = r repository.find 1
book_2 = Book.new title: 'XP'
book = repository.update 1, book_2

```

Is this fine?

---

<div class="post-metadata">

**Author:** ![davydovanton](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/davydovanton/32/162_2.png) [@davydovanton](https://discourse.hanakai.org/u/davydovanton)\
**Post date:** [May 5, 2018, 11:05am UTC](https://discourse.hanakai.org/t/updating-hanami-entity/444/2 "2018-05-05T11:05:16Z")

</div>

hey, I answered to this question in this SO page 🙂

> <https://stackoverflow.com/questions/49142802/how-to-update-only-changed-attributes-in-hanami-model/50157021#50157021>

---

<div class="post-metadata">

**Author:** ![hectorsq](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/hectorsq/32/280_2.png) [@hectorsq](https://discourse.hanakai.org/u/hectorsq)\
**Post date:** [May 5, 2018, 4:32pm UTC](https://discourse.hanakai.org/t/updating-hanami-entity/444/3 "2018-05-05T16:32:36Z")

</div>

This is what I was looking for:

**"hanami entity is an immutable data structure"**

Thank you very much for your clarification.
