Giter Site home page Giter Site logo

Comments (6)

richmolj avatar richmolj commented on September 14, 2024

@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.

zoran avatar zoran commented on September 14, 2024

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.

richmolj avatar richmolj commented on September 14, 2024

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.

zoran avatar zoran commented on September 14, 2024

Yes that would be great

from jsonapi_compliable.

richmolj avatar richmolj commented on September 14, 2024

@zoran this is in master, I will release a new version tonight

from jsonapi_compliable.

richmolj avatar richmolj commented on September 14, 2024

Fixed in 0.5.5

from jsonapi_compliable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.