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

Add collection version of remote methods #2

@dmcinnes

Description

@dmcinnes

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions