Skip to content

Commit 5a7e8a6

Browse files
committed
Readme. Add Aliases section
1 parent 0152004 commit 5a7e8a6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,26 @@ field :actions_taken, :integer, default: 0
365365
field :joined_at, :datetime, default: -> { Time.now }
366366
```
367367

368+
#### Aliases
369+
370+
It might be helpful to define an alias for already existing field when
371+
naming convention used for a table differs from conventions common in
372+
Ruby:
373+
374+
```ruby
375+
field firstName, :string, alias: :first_name
376+
```
377+
378+
This way there will be generated
379+
setters/getters/`<name>?`/`<name>_before_type_cast` methods for both
380+
original field name (`firstName`) and an alias (`first_name`).
381+
382+
```ruby
383+
user = User.new(first_name: 'Michael')
384+
user.first_name # => 'Michael'
385+
user.firstName # => 'Michael'
386+
```
387+
368388
#### Custom Types
369389

370390
To use a custom type for a field, suppose you have a `Money` type.

0 commit comments

Comments
 (0)