“idInjection”时,模型ID无法识别:false,某些属性具有“id”:true

时间:2015-04-07 19:20:49

标签: android loopbackjs strongloop

我制作了一个POC Android App来测试这种行为。

看起来Loopback的Android SDK在某些操作中无法识别模型的Id字段。

我编写了一个基本操作来删除MySQL DB上的记录。首先,我收集了一个我知道存在于表格中的对象" findById"我在onSuccess回调中调用destroy()方法。 destroy()方法返回内部服务器错误异常。

这是我的模型类代码 loopbackpoc-booking.json

{
  "name": "loopbackpocBooking",
  "base": "PersistedModel",
  **"idInjection": false**,
  "mysql": {
    "schema": "loopback_poc",
    "table": "loopbackPOC_bookings"
  },
  "properties": {
    "bookBoSync": {
      "type": "Number",
      "required": false,
      "length": null,
      "precision": 3,
      "scale": 0,
      "mysql": {
        "columnName": "book_bo_sync",
        "dataType": "tinyint",
        "dataLength": null,
        "dataPrecision": 3,
        "dataScale": 0,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "bookCdBooking": {
      "type": "Number",
      **"id": true**,
      "required": true,
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "book_cd_booking",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "bookCdItinerary": {
      "type": "Number",
      "required": true,
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "book_cd_itinerary",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "bookDtSync": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "book_dt_sync",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "bookNrAmount": {
      "type": "Number",
      "required": false,
      "length": null,
      "precision": 22,
      "scale": null,
      "mysql": {
        "columnName": "book_nr_amount",
        "dataType": "double",
        "dataLength": null,
        "dataPrecision": 22,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

模型类(BookingPOCModel.java)

public class BookingPOCModel extends Model {

    protected int bookCdBooking;
    protected int bookCdItinerary;
    protected double bookNrAmount;
    protected Boolean bookBoSync;
    protected String bookDtSync;

    public int getBookCdBooking() {
        return bookCdBooking;
    }

    public void setBookCdBooking(int bookCdBooking) {
        this.bookCdBooking = bookCdBooking;
    }

    public int getBookCdItinerary() {
        return bookCdItinerary;
    }

    public void setBookCdItinerary(int bookCdItinerary) {
        this.bookCdItinerary = bookCdItinerary;
    }

    public double getBookNrAmount() {
        return bookNrAmount;
    }

    public void setBookNrAmount(double bookNrAmount) {
        this.bookNrAmount = bookNrAmount;
    }

    public Boolean getBookBoSync() {
        return bookBoSync;
    }

    public void setBookBoSync(Boolean bookBoSync) {
        this.bookBoSync = bookBoSync;
    }

    public String getBookDtSync() {
        return bookDtSync;
    }

    public void setBookDtSync(String bookDtSync) {
        this.bookDtSync = bookDtSync;
    }
}

活动中有趣的代码:

private void deleteData(final RestAdapter adapter, BookingPOCRepository repository) {
    repository.findById(28, new ObjectCallback<BookingPOCModel>() {
        @Override
        public void onSuccess(final BookingPOCModel object) {
            Log.i("findById", "Got object ID: " + object.getBookCdBooking());
            object.destroy(new VoidCallback() {
                @Override
                public void onSuccess() {
                    Log.i("deleteData", "Deleted object ID: " + object.getBookCdBooking());
                }

                @Override
                public void onError(Throwable t) {
                    Log.e("deleteData", "Failed to delete object ID: " + object.getBookCdBooking() + " - " + t);
                }
            });
        }

        @Override
        public void onError(Throwable t) {
            Log.e("findById", "Couldn't get object.");
        }
    });
}

我确信数据库中有一条记录&#34; bookCdBooking&#34;:28 。该字段是标识为&#34; id&#34;在模型中。从DB正确收集模型,但在调用destroy()方法时返回500错误。

我已经调试过看到实际在通话中生成的网址,我得到了这个:

http://192.168.1.10:3000/api/loopbackpocBookings/null?bookDtSync=null&id=null&bookBoSync=null&bookNrAmount=100.0&bookCdItinerary=1&bookCdBooking=28

请注意ID应该在哪里 null

我已经检查了我从DB获得的模型对象(在代码中命名为#34;对象&#34;)和&#34; id&#34; property为null。我想知道这是否与这个问题有关。

enter image description here

仍在等待调查,但似乎在使用save()方法更新现有模型时也会出现此问题。

有什么想法吗?

0 个答案:

没有答案