0
我有一个病人的骨干模型,我可以用它来从我的Mongo数据库中提取病人。但除了通过身份证进行投票之外,我希望能够通过名称将其拉出来。我能想到的唯一办法就是做类似这样的事情:骨干不通过ID得到模型
class Thorax.Models.Patient extends Thorax.Model
urlRoot: '/api/patients'
idAttribute: '_id'
fetch: (options = {}) ->
if @get 'first' # has first name, lookup by that instead of id
@urlRoot = '/api/patients/by_name/' + (@get 'first') + '/' + (@get 'last')
@set '_id', ''
super options
但是重写urlRoot看起来很糟糕。有没有另一种方法来做到这一点?