Search code examples
javascriptsqldatabasesproutcore

How can two SC.RecordArray types be concatenated in Sproutcore?


The following is the code :

        queryTree = SC.Query.local('Tree.Category',
        "categoryId = {categoryId}", {
            categoryId: this.get('guid'),
            orderBy: "name ASC"
        });
        queryNote = SC.Query.local('Tree.Note',
            "categoryId = {categoryId}", {
            categoryId: this.get('guid'),
            orderBy: "name ASC"
        });
        var arrayCategory = Tree.store.find(queryTree);
        var arrayNote = Tree.store.find(queryNote);
        //Concatenate arrayCategory to arrayNote

I want to return a new array of records that appends the results to arrayCategory and arrayNote. I went through the documentation, but there doesn't seem to be a concatenate function.


Solution

  • I thought I would have to concatenate the two search results. But I fixed the problem this way: For every record in Tree.Note and Tree.Category I created a field called isChild and set it as YES in the former and NO in the latter. Further I changed the return value of the function to this:

    return Tree.store.find(SC.Query.local(['Tree.Category','Tree.Note'],
            "categoryId = {categoryId}", {
                categoryId: this.get('guid'),
                orderBy: 'isChild, name',
    
            }))
    

    EDIT : Something's still wrong. Could someone suggest how should change this?