$goQuery is only returning a single value

161 Views Asked by At

I have a scope model called person that has a firstname, lastname and fullname. My goQuery works with this:

$scope.person = $goQuery('person', { userName: $scope.person.findme }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();

The only problem I'm having is that it only populates the value for the field I'm searching and not the whole model. What am I missing?

2

There are 2 best solutions below

3
c m a c On

$scope.person.findme throws an error because $scope.person is not yet defined. I'm not sure how this is working at all.

Here's a working example:

$scope.person = $goQuery('person', 'person', { userName: 'user1' }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();

$scope.person.$add({ userName: 'user1', fname: 'a', lname: 'b'});
$scope.person.$add({ userName: 'user2', fname: 'c', lname: 'd'});
$scope.person.$add({ userName: 'user3', fname: 'e', lname: 'f'});
window.person = $scope.person;

If you look at the model on window.person you should see user1's ID and their data under it.

0
Rudy Hinojosa On

Ok. Thank you Colin MacDonald. This is how you return results into your scope: HTML CODE:

 <label>Find User:</label>
    <input type="text" ng-model="person.findme" placeholder="Enter Full Name to Search..." />
    <input type="button" id="Find" value="Search" ng-click="Find()" />

JAVA SCRIPT:

 $scope.Find = function () {
  console.log('entering find method...')
  $scope.person = $goQuery('person', { userName: $scope.person.findme }, { limit: 1 }).$sync();
       $scope.person.$on('ready', function () {
            var id = $scope.person.$$index[0];
                if (!id) {
                   // no results found
                   return;
                }
       $scope.person = $scope.person[id];
                       $scope.person.id = id;
       });
       };