Coder Social home page Coder Social logo

Nested collection paths about maglev HOT 6 OPEN

jespr avatar jespr commented on August 16, 2024
Nested collection paths

from maglev.

Comments (6)

clayallsopp avatar clayallsopp commented on August 16, 2024

Hmm I see, yeah there should be a way to do that. Another way it could work is along the lines of

belongs_to :event

collection_path event_path + "/photos/:id"

I'd welcome a PR for either, if you're interested?

as a workaround for now, you can also define a function event_id and it'll be used in the URL:

def event_id
  self.event.id
end

from maglev.

jespr avatar jespr commented on August 16, 2024

I'll take a stab at it and get back to you with a PR :)

from maglev.

jespr avatar jespr commented on August 16, 2024

@clayallsopp so you're saying that added def event_id would make my collection_path and member_path being /events/:event_id/photos and /events/:event_id/photos/:id work? I can't seem to get that working either..

from maglev.

jespr avatar jespr commented on August 16, 2024

I can get it working if i manually pass in the params in the find or find_all methods, but I can't by just defining the method in the model

from maglev.

clayallsopp avatar clayallsopp commented on August 16, 2024

Ahh I see, nevermind, I didn't totally think through the example, sorry!

What should work is this:

class Event < Maglev::Model
  remote_attributes :id, :name

  has_many :photos,
    collection_path: "/events/:id/photos",
    member_path: "/events/:event_id/photos/:id"

  def event_id
    self.id
  end
end

event = Event.new(...)

event.photos.find_all do |photos|
end

event.photos.find(13) do |photo|
end

The facebook example does something similar: https://github.com/clayallsopp/maglev/blob/master/examples/FacebookGraph/app/models/user.rb

from maglev.

jespr avatar jespr commented on August 16, 2024

Never got to continue working on this one. Moved to San Francisco recently, and have been tied up in getting settled. I do plan on implementing nested collection paths, though

And thanks your your reply!

from maglev.

Related Issues (11)

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.