如何在Backendless 4.0中使用JAVA保存关系对象?

时间:2017-10-01 15:37:12

标签: java android database backendless

  

(使用BACKENDLESS 4.0保存关系数据)

我想以一对一的关系保存数据。 示例:-person_table与adress_table有关系 数据保存在person_table和address_table中,没有关系。怎么能做到这个? #backendless4.0

Adress newAdress= new Adress();
    newAdress.setAdress("43 Street");
    newAdress.setPersonId(Person);
    Backendless.Persistence.save(newAdress, new AsyncCallback< Adress >() {
        @Override
        public void handleResponse(Adress response) {
        }

        @Override
        public void handleFault(BackendlessFault fault) {
            fault.getMessage();
        }
    });

1 个答案:

答案 0 :(得分:1)

我找到了结果: 要在backendless 4.0中保存关系,您需要先保存对象并保存之后的关系。

参考链接1:ADD RELATION WITH OBJECTS 参考链接2:save object with relation using REST API

Person personObject = // personObject retrieval is out of scope in this example
        Adress objectAdress = // addressObject retrieval is out of scope in this example
        ArrayList< Person > personCollection = new ArrayList< Person >();
        personCollection.add( personObject );
        Backendless.Data.of( Adress.class ).addRelation( objectAdress, "personId:Adress:n", personCollection,
            new AsyncCallback<Integer>()
            {
                @Override
                public void handleResponse( Integer response )
                {
                    progressDialog.dismiss();
                    Log.i( "MYAPP", "related objects have been added");
                }

                @Override
                public void handleFault( BackendlessFault fault )
                {

                }
            } );