No data found with find() function

Hi,
I have a problem to retrieve my data, whatever the entity invoked.
The findById(), first () or last () functions returns my searched record.
But the find() function returns nothing.
The length property of my collection is set to 0, while my tables has up to 16 records. Data all appear in the web console.

The code used is :

var responder:IResponder = new mx.rpc.Responder(

					function( evt:ResultEvent ):void

					{

						collection = evt.result as BackendlessCollection

						trace( "collection length : " + collection );

						

						

					},

					function( evt:FaultEvent ):void

					{

						trace( "Error loading - " + evt.fault.faultDetail );

					});

				

				

				Backendless.Data.of( Traction ).find( null, responder ); 

Of course, Backendless is initialized and the classes mapped.

Thank you in advance,

Christophe

Hi Christophe,

The code snippet you provided declares 2 FaultEvent handler functions. Is this an oversight?

Can you also show the mapping code for the Traction class/table?

Finally, what is the name of that table on the server-side?

Regards,
Mark

Hi Mark,

The second FaultEvent handler functions was just a copy/paste error…

This is the Traction class/table and the table has the same name on the server-side.

/**
 * Created by the awesome Backendless Code Generator on 11/3/14.
 */
package com.APP_NAME.data
{
  import com.backendless.Backendless;
  import com.backendless.BackendlessUser;
  import com.backendless.data.BackendlessCollection;


  import mx.collections.ArrayList;
  import mx.collections.IList;


  import mx.rpc.IResponder;
  import mx.rpc.Responder;
  import mx.rpc.events.FaultEvent;
  import mx.rpc.events.ResultEvent;


  public class Traction
  {
    public var ___class = "Traction";
    public var __meta;


    private var _created:Date;
    private var _objectId:String;
    private var _ownerId:String;
    private var _InstrucLiv:String;
    private var _prixTraction:Number;
    private var _instrucEnlev:String;
    private var _updated:Date;
    private var _reference:String;
    private var _addressEnlev:BackendlessCollection;
    private var _addressLiv:BackendlessCollection;
    
    public function Traction()
    {
      AppInit.initialize();
    }
                                        
    public function get created():Date
    {
      return _created;
    }


    public function set created( value:Date ):void
    {
      this._created = value;
    }
                                        
    public function get objectId():String
    {
      return _objectId;
    }


    public function set objectId( value:String ):void
    {
      this._objectId = value;
    }
                                        
    public function get ownerId():String
    {
      return _ownerId;
    }


    public function set ownerId( value:String ):void
    {
      this._ownerId = value;
    }
                                        
    public function get InstrucLiv():String
    {
      return _InstrucLiv;
    }


    public function set InstrucLiv( value:String ):void
    {
      this._InstrucLiv = value;
    }
                                        
    public function get prixTraction():Number
    {
      return _prixTraction;
    }


    public function set prixTraction( value:Number ):void
    {
      this._prixTraction = value;
    }
                                        
    public function get instrucEnlev():String
    {
      return _instrucEnlev;
    }


    public function set instrucEnlev( value:String ):void
    {
      this._instrucEnlev = value;
    }
                                        
    public function get updated():Date
    {
      return _updated;
    }


    public function set updated( value:Date ):void
    {
      this._updated = value;
    }
                                        
    public function get reference():String
    {
      return _reference;
    }


    public function set reference( value:String ):void
    {
      this._reference = value;
    }
                                        
    public function get addressEnlev():BackendlessCollection
    {
      return _addressEnlev;
    }


    public function set addressEnlev( value:* ):void
    {
      if( value is Array )
      {
        initAddressEnlevCollection();
        _addressEnlev.currentPage.addAll( new ArrayList( value ) )
      }
      else if( value is BackendlessCollection )
      {
        this._addressEnlev = value;
      }
      else if( value is IList )
      {
        initAddressEnlevCollection();
        _addressEnlev.currentPage.addAll( value );
      }
    }
                                                
    public function get addressLiv():BackendlessCollection
    {
      return _addressLiv;
    }


    public function set addressLiv( value:* ):void
    {
      if( value is Array )
      {
        initAddressLivCollection();
        _addressLiv.currentPage.addAll( new ArrayList( value ) )
      }
      else if( value is BackendlessCollection )
      {
        this._addressLiv = value;
      }
      else if( value is IList )
      {
        initAddressLivCollection();
        _addressLiv.currentPage.addAll( value );
      }
    }
                                                
    public function loadAddressEnlev( responder:IResponder = null ):void
    {
      if( _addressEnlev == null )
        Backendless.Data.of( Traction ).loadRelations( this, [ "addressEnlev" ], responder );
    }
                                            
    public function initAddressEnlevCollection():void
    {
      _addressEnlev = new BackendlessCollection();
      _addressEnlev.setEntityClass( Traction );
    }


    public function addItemToAddressEnlev( item:AddressTraction ):void
    {
      if( _addressEnlev == null)
        initAddressEnlevCollection();


      _addressEnlev.addItem( item );
    }


    public function removeItemFromAddressEnlev( item:AddressTraction ):Boolean
    {
      if( _addressEnlev == null )
        return false;


      return _addressEnlev.removeItem( item );
    }
                                                    
    public function loadAddressLiv( responder:IResponder = null ):void
    {
      if( _addressLiv == null )
        Backendless.Data.of( Traction ).loadRelations( this, [ "addressLiv" ], responder );
    }
                                            
    public function initAddressLivCollection():void
    {
      _addressLiv = new BackendlessCollection();
      _addressLiv.setEntityClass( Traction );
    }


    public function addItemToAddressLiv( item:AddressTraction ):void
    {
      if( _addressLiv == null)
        initAddressLivCollection();


      _addressLiv.addItem( item );
    }


    public function removeItemFromAddressLiv( item:AddressTraction ):Boolean
    {
      if( _addressLiv == null )
        return false;


      return _addressLiv.removeItem( item );
    }
                                                    
    public function save( responder:IResponder = null ):void
    {
      Backendless.Data.of( Traction ).save( this, responder );
    }


    public function remove( responder:IResponder = null ):void
    {
      Backendless.Data.of( Traction ).remove( this, new Responder(
              function( evt:ResultEvent ):void
              {
                objectId = null;


                if( responder != null )
                  responder.result( evt );
              },
              function( evt:FaultEvent ):void
              {
                if( responder != null )
                  responder.fault( evt );
              }
      ));
    }
  }
}

Regards,

Christophe

Christophe,

Could you please send me by email the AppInit.as file? My email address is mark@backendless.com

Thanks,
Mark

Hi Christophe,

The code is actually returning data. What’s not working (due to a bug) is the initialization of the “totalObjects” property in the BackendlessCollection instance returned from the server.

I will commit a bug fix in a moment.

Regards,
Mark

Hi Mark,

I thank you so much.
Indeed, the REST Console returned data.

Regards,

Christophe

Hi Christophe,

For the sake of closure and for the benefit of other users, here’s working sample of the code:

    public function loadTractions():void
    {
      var responder:IResponder = new Responder(
                     function( evt:ResultEvent ):void
                     {
                       trace( "got data" );
                       var tractions:BackendlessCollection = evt.result as BackendlessCollection;
                       trace( "total objects - " +  tractions.totalObjects );


                       for( var i:int = 0; i < tractions.currentPage.source.length; i++ )
                        trace( "object ID - " + tractions.currentPage[ i ].objectId );
                     },
                     function( evt:FaultEvent ):void
                     {
                       trace( "error " + evt.fault.faultDetail );
                     });


      Backendless.Data.of( Traction ).find( null, responder );
    }

Hi Mark,

I thank you for your help, but I continued my investigations, and I found the same issue (an empty backendlessCollection), when I try to access the children of an entity, while the entity has 4 children and the “auto load” checkBox is selected in the Backendless Console.

The aforementioned class/table Traction is a child of the class/table Transport
and Transport has a multiple objects relationship ‘tractions’.

Transport.tractions[Traction, Traction, Traction]

When I save a Transport instance with 4 Traction pushed in ‘tractions’ BackendlessCollection property, registration is done perfectly : one Transport, 4 Traction(s)

But when I load a Transport record and I try to access its children, the returning collection is empty.

var transports:BackendlessCollection = evt.result as BackendlessCollection;
trace("total tractions - " + Transport(transports.currentPage[ 0 ]).tractions.totalObjects);
// output : total tractions - 0 // while they're 4 in db

The ‘auto load’ is not it enough to repatriate children?

I can’t either access it like this:

trace(Transport(transports.getItemAt(0)).objectId));

The output I get is : RangeError: Index ‘0’ specified is out of bounds. while BackendlessCollection has getItem() function (as he extends ArrayCollection).

Can we only access transports and properties by using currentPage/ArrayCollection property whereas BackendlessCollection would be reserved for the data paging mechanism?

Thanks,
Regards,
Christophe

Hi Christophe,

Is “autoLoad” enabled now? Please let me know and I will try it from my side.

Regards,
Mark

Hi Mark,

“auto load” checkbox is selected in the web console for ‘tractions’ property of Transport table.

Regards,

Christophe

Hi Christophe,

I am getting your data with related objects just fine. Here’s the code:

    public function loadTransports():void
    {
      var responder:IResponder = new Responder(
                     function( evt:ResultEvent ):void
                     {
                       trace( "got data" );
                       var transports:BackendlessCollection = evt.result as BackendlessCollection;
                       trace( "total objects - " +  transports.totalObjects );


                       for( var i:int = 0; i < transports.currentPage.source.length; i++ )
                       {
                         var transport:Transport = transports.currentPage.getItemAt( i );


                         trace( "Transport - " + transport.objectId );
                         trace( "Transport's tractions. Received objects: " + transport.tractions.length );
                       }
                     },
                     function( evt:FaultEvent ):void
                     {
                       trace( "error " + evt.fault.faultDetail );
                     });


      Backendless.Data.of( Transport ).find( null, responder );
    }

And here’s the output:

total objects - 4
Transport - 63EEAD17-BD2E-969B-FF49-36B7EC145800
Transport’s tractions. Received objects: 4
Transport - 09DFB141-E65F-8234-FFDF-A355E8DE4E00
Transport’s tractions. Received objects: 4
Transport - B07C2AF4-AE6D-3162-FF13-1CA3B530FD00
Transport’s tractions. Received objects: 4
Transport - 0B3D7C39-8D47-21A2-FF19-19FD1E253400
Transport’s tractions. Received objects: 4

Since I didn’t have the code for your Transport class, I create a super basic one and mapped it in AppInit.as:

  public dynamic class Transport
  {
    public var tractions:Array;
  } 

Hi Mark,

Yes, I also got these results with a dynamic class, but why can not I access Transport’s tractions with the class generated by the console?

I of course need access at the same time the other properties of my table Transport. Should I rewrite my classes when I want to use relations?

Regards,
Christophe

You should be able to. I just generated code for the tables in my own project and was able to retrieve data with the autoLoad option. Send me an email with the generated code for your project and I will try it here with it too.

Regards,
Mark

Hi Mark,

Since my ‘tractions’ property is BackendlessCollection (and not Array) type, I was able to retrieve related data by using again currentPage property.

trace(transport.tractions.currentPage.length) // output : 4;

It’s ok!

My thanks for the time spent helping me.

Best regards,

Christophe