Comments (6)
@zoran I think this is probably best left to the lower-level DSL, which you can customize with a block. We wouldn't be dealing with @object
at this point but @objects
(because you could be hitting an index endpoint listing all users, then want all addresses for all users). That's available in the lower-level DSL:
class UserResource
type :users
has_many :addresses, options do
scope do |users|
Address.where(["zip LIKE ?", users.map(&:zip))
end
end
end
Does that work for you? Note this will override any scope
option you pass to has_many
.
from jsonapi_compliable.
mhh, I get missing keywords: scope
and I have to use an empty scope option:
has_many :addresses,
scope: -> {} do
scope do |users|
Address.where(["zip LIKE ?", users.map(&:zip))
end
end
from jsonapi_compliable.
Yeah, I should definitely make it so you can pass EITHER scope
key, OR a scope
block. primary_key/foreign_key
would still be used to assign the objects to each other, though.
After that I'd say the abstraction still looks correct to me. Would just making scope
optional sound good to you?
from jsonapi_compliable.
Yes that would be great
from jsonapi_compliable.
@zoran this is in master, I will release a new version tonight
from jsonapi_compliable.
Fixed in 0.5.5
from jsonapi_compliable.
Related Issues (20)
- Add before_commit_abort hook
- Add a rollback method on resources to handle manually defining a transaction HOT 2
- N+1 Query Detected
- N+1 Query with Bullet HOT 1
- Detect N+1 Query
- Association arguments and scope HOT 1
- Pass in config to adapters HOT 3
- Add association validation errors on unsuccessful sidepost
- destroyed objects rendering HOT 4
- Posting to nested routes HOT 5
- Attributes/Persistence logic does not support Mongoid HABTM HOT 2
- Attributes/Persistence not friendly to noSQL embedding HOT 4
- Sideloading fails if (nested) sideloads have the same name HOT 1
- Need to declare jsonapi resource: in every controller when inheriting mix-in from ApplicationController HOT 1
- No interface to discriminently disable pagination for resource HOT 3
- Sequel adapter HOT 3
- Sideloading / include no longer works in newest version HOT 2
- having filter guards call controller method causes issues when resource is sideloaded HOT 1
- Disassociating a required belongs_to should raise error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi_compliable.