Skip to content
This repository has been archived by the owner on Jul 11, 2020. It is now read-only.

Add collection version of remote methods #2

Open
dmcinnes opened this issue Sep 26, 2014 · 1 comment
Open

Add collection version of remote methods #2

dmcinnes opened this issue Sep 26, 2014 · 1 comment

Comments

@dmcinnes
Copy link
Collaborator

From a client POV is there a difference between remoted and associated? Can they be consolidated.

For example

GET /v1/posts/1/comments.json # associated
GET /v1/posts/1/top_comments.json # remoted (collection)
GET /v1/posts/1/statistics.json # remoted (single record)

We can detect if it's a collection vs. a single record. (Maybe ActiveResource already does?)
In fact, we could use has_many and has_one/belongs_to to implement remoted instance methods from the client-side

Add collection version of remote methods

Maybe remoted is only for class level methods? (how are they different from scopes?)

GET /v1/posts/by_popularity

We do have scopes and instance-level remote methods but there could be a case where a collection (class-level) based remote method would be useful.

class Post < ActiveRecord::Base
  def self.by_popularity
     order_by(:vists)
  end
end

This by_popularity method is a trivial example (tht could be a scope -- uh, from the client POV, why wouldn't it just be a scope?) but imagine a query that is much more computationally expensive across all Posts

@dmcinnes
Copy link
Collaborator Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant