Collection prototype

Hello, I have a field that is a reference to another model…

  costumerId:{
type:String,
optional:true,    
autoform: {
    type: "select2",
    options: function () {
        return Costumer.find().map(function (c) {
            return {label: c.name, value: c._id};
        });
    }
}  

as you can see, im using a function to populate the options… this function is used in many places, so i would like to attach a function to my Costumer collection… so I could use Costumer.quickList() to get this list…
how can i do that?

I don’t understand, whats the problem with my post?

(responded too fast, thank you ahref)

I withdrew my post, which leaves that message because I tried to answer your question without reading it. It doesnt refer to your topic.

However I shall try to answer it now:

You should be able to store that query in the Collection object.

 Costumer.quickList = function() {
    //stuff
    };

Or throw the function inside another object.

App.Forms.customerQuickList = function() {
}

@vjau that isn’t quite what they are asking.

They want to call a method located on the collection that returns the result of that function, the mapped list. With your transform they’d still need a function which maps the .find() to an array of result.quickLists. I hope that makes sense.

2 Likes

Wow, so simple! thanks!!