Re: [batmanjs] Nested routes and object crud operations.

25 views
Skip to first unread message

Robert Mosolgo

unread,
Jul 26, 2014, 10:20:21 PM7/26/14
to batm...@googlegroups.com
Hi Andrew, 

I think it's going to look for passenger.booking_id and it's not smart enough to look for passenger.booking.id

Try setting the booking_id: 

passenger.set('booking_id', booking.get('id'))

Does that work for you? 

Thanks for reporting this bug, I've opened a github issue for it: https://github.com/batmanjs/batman/issues/1104

robert




On Sat, Jul 26, 2014 at 6:55 PM, Andrew Zielinski <andrew.zi...@gmail.com> wrote:
Hi,

I'm new to Batman.js so I'm hoping somebody can help me out.

When I call destroy on a model I want it to call a nested url. It seems to work OK when I call save.

Here is my class:
class App.Passenger extends Batman.Model
  @resourceName: 'passenger'
  @storageKey: 'passengers'

  @persist Batman.RailsStorage
  @belongsTo 'booking'

  @encode 'id', 'first_name', 'last_name', 'weight', 'baggage_weight'
  @encode 'booking_id', encode: false
  @encodeTimestamps()
  @urlNestsUnder 'booking'


And here is the code that I have in a view.

  removePassenger: (booking, passenger) ->
    passenger.set('booking', booking)
    passenger.destroy (err, obj) =>
      if err
        throw err unless err instanceof Batman.ErrorsSet
      else
        @get("controller.booking.passengers").remove(obj)


The call that is made is DELETE http://localhost:3000/passengers/8.json instead of DELETE http://localhost:3000/bookings/1/passengers/8.json.
Any help would be appreciated.


Andrew



--
You received this message because you are subscribed to the Google Groups "batman.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to batmanjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Zielinski

unread,
Aug 2, 2014, 11:10:51 PM8/2/14
to batm...@googlegroups.com, rdmo...@gmail.com
That didn't work for me either.
Works find when I try to save the object.

Thanks,

Andrew

Andrew Zielinski

unread,
Aug 2, 2014, 11:27:49 PM8/2/14
to batm...@googlegroups.com, rdmo...@gmail.com
Sorry. Just a had a typo. Yes. That does work for me. 
Thanks
Andrew

Robert Mosolgo

unread,
Aug 3, 2014, 11:24:02 AM8/3/14
to Andrew Zielinski, batm...@googlegroups.com
Great! I'll try to get that nested-ids issue worked out before the next batman.js version.
Reply all
Reply to author
Forward
0 new messages