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

Document scope feature #10

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ Way nicer, right?
Just like AMS, USerializer supports `has_one` and `has_many`
relationships

### Collection Attributes Filtering

For `has_many` relationships, USerializer allow you to serialize only
part of the collection that matches some criterias.
It relies on the ActiveRecord `scope` feature :

```ruby
class Product < ActiveRecord::Base
has_many :variants
end

class Variant < ActiveRecord::Base
belongs_to :product

scope :available, -> { where(delete_at: nil) }
end

class ProductSerializer < USerializer::BaseSerializer
has_many :variants, scope: :available
end

class VariantSerializer < USerializer::BaseSerializer
end
```

### Serialized Output

The following outputs will be based an on our `Order` object in
Expand Down
Loading