2

I am using CanJS for a web application. I want to know how to implement search. I have implemented findAll but i want to implement findOne based on the name and not id.

var Library = can.Model({
    findAll:    "GET /libraries",
    findOne:    "GET/libraries/{id}",
    create:     'POST /libraries',
    update:     'PUT /libraries/{id}',
    destroy:    'DELETE /libraries/{id}'
}, {});

I want to implement findOne based on the name and not on ID. Can some one help me. I came accross Underscore.js. What are the other alternatives of finding based on the name.

{ "id" : 1, "name" : "CanJS", "web" : "http://canjs.us", "logo": "img/can.png" },

This is how the items in library look like.

ramblinjan
  • 6,578
  • 3
  • 30
  • 38
Shraddha Shravagi
  • 1,096
  • 1
  • 9
  • 22

3 Answers3

1

You can use it without rewrite findOne function:

MyModel.findOne({id:15,name:'canjs'})

the request will be mayendpoint?id=15&name=canjs

the Id is mandatory for RESTFUL resource if you want to keep it.

Cherif BOUCHELAGHEM
  • 1,126
  • 2
  • 14
  • 21
0

You can implement findOne as you like, e.g. findOne: 'GET /libraries/name/{name}'. See API documentation.

Petr Felzmann
  • 1,271
  • 4
  • 19
  • 39
0

You can implement findOne with a function of your own as written here

Thomas
  • 1,410
  • 10
  • 24