-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add migration documents from ASM #143
Conversation
e932206
to
7ffbf3a
Compare
@okuramasafumi
|
Also I want to mention that file name should be something like "migrate_from_jbuilder", not just "jbuilder".
I think we need migration document for real-world, complex cases. For example, with jbuilder we use partials a lot so I'd like to mention how to write partial-like serializer with Alba.
It's important to mention that Alba doesn't have all the features AMS or jbuilder have. For example, Alba doesn't support cache. I think it's fair to mention some feature Alba doesn't have. |
@okuramasafumi |
@okuramasafumi |
@tashirosota Yeah just adding a document for AMS is fine. |
@okuramasafumi |
b3bb901
to
81dc546
Compare
|
||
This guide is aimed at helping ActiveModelSerializers users transition to Alba, and it consists of three parts: | ||
|
||
1. Basically serialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Basically serialization | |
1. Basic serialization |
This guide is aimed at helping ActiveModelSerializers users transition to Alba, and it consists of three parts: | ||
|
||
1. Basically serialization | ||
2. Complexity serialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Complexity serialization | |
2. Complex serialization |
end | ||
|
||
class Article | ||
attr_accessor :id, :title, :body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attr_accessor :id, :title, :body | |
attr_accessor :user_id, :title, :body |
end | ||
``` | ||
|
||
## 1. Basically serialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 1. Basically serialization | |
## 1. Basic serialization |
=> { | ||
user: { | ||
id: id, | ||
created_at: created_at, | ||
updated_at: updated_at | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> { | |
user: { | |
id: id, | |
created_at: created_at, | |
updated_at: updated_at | |
} | |
} | |
# => { | |
# user: { | |
# id: id, | |
# created_at: created_at, | |
# updated_at: updated_at | |
# } | |
# } |
When we print output, it should be commented out to make it clear that it's no actually code
} | ||
``` | ||
|
||
#### When Alba |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### When Alba | |
#### Alba |
=> { | ||
email: email | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> { | |
email: email | |
} | |
# => { | |
# email: email | |
# } |
} | ||
``` | ||
|
||
#### When Alba |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### When Alba | |
#### Alba |
=> { | ||
:id=>1, | ||
:created_at=>created_at, | ||
:updated_at=>updated_at, | ||
:custom_params=>{ | ||
:given_params=>{ | ||
:a=>:b | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> { | |
:id=>1, | |
:created_at=>created_at, | |
:updated_at=>updated_at, | |
:custom_params=>{ | |
:given_params=>{ | |
:a=>:b | |
} | |
} | |
} | |
# => { | |
# :id=>1, | |
# :created_at=>created_at, | |
# :updated_at=>updated_at, | |
# :custom_params=>{ | |
# :given_params=>{ | |
# :a=>:b | |
# } | |
# } | |
# } |
=> { | ||
:id=>1, | ||
:created_at=>created_at, | ||
:updated_at=>updated_at, | ||
:custom_params=>{ | ||
:a=>:b | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> { | |
:id=>1, | |
:created_at=>created_at, | |
:updated_at=>updated_at, | |
:custom_params=>{ | |
:a=>:b | |
} | |
} | |
# => { | |
# :id=>1, | |
# :created_at=>created_at, | |
# :updated_at=>updated_at, | |
# :custom_params=>{ | |
# :a=>:b | |
# } | |
# } |
@tashirosota I suggested multiple changes including fixing typos and commenting out outputs. https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/howto/serialize_poro.md |
0b1369a
to
0eeb5d2
Compare
Example clsss is included `ActiveModel::Model`, because [serializing PORO with AMS is pretty hard](https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/howto/serialize_poro.md).This example also works with ActiveRecord. | ||
|
||
```rb | ||
class User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@okuramasafumi
Thanks for review!
I can't find how to serialize with object included ActiveModel::Model.
https://github.com/rails-api/active_model_serializers/tree/0-10-stable#high-level-behavior
SomeResource < ActiveModelSerializers::Model
is a bad example of both compatibility, so I'd like to use SomeResource < ActiveRecord::Base
, but is that okay?
Like this.
class User < ActiveRecord::Base
# columns: id, created_at, updated_at
has_one :profile
has_many :articles
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply.
Yes, using AR::Base
is fine.
c291bf9
to
8625ebc
Compare
Codecov Report
@@ Coverage Diff @@
## main #143 +/- ##
==========================================
+ Coverage 99.37% 99.40% +0.02%
==========================================
Files 9 9
Lines 322 336 +14
==========================================
+ Hits 320 334 +14
Misses 2 2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
#98