Search code examples
javaandroidpostgresqlstronglooploopback

Error: Model::findById require argument id loopback android


I am new to loopback and I have a problem with it. I have created and managed a Postgres database and everything seems to work fine. The database is created by boot files in json and contains the needed values.

But when I want to execute findById method, I get the following issue :

Error for the request GET /api/members/1?id=1 : Error: Model::findById require the id argument

the model definition is :

{
    "name": "Member",
    "strict": true,
    "idInjection": true,
    "base": "User",
    "options": {
       "validateUpsert": true
    },
    "properties": {
    "firstname": {
    "type": "string",
    "required": true
    },
    "lastname": {
    "type": "string",
    "required": true
    },
    "questiontype": {
    "type": "number",
    "required": true
    },
    "questionanswer": {
    "type": "string",
    "required": true
    }
    },
    "validations": [],
    "relations": {
    "issues": {
       "type": "hasMany",
       "model": "Issue",
       "foreignKey": "authorId"
    }

And I call findById from my LoginActivity :

 connect_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RestAdapter restAdapter = new RestAdapter(getApplicationContext(), "http://" + MY_IP + ":3000/api");
            MemberRepository memberRepo = restAdapter.createRepository(MemberRepository.class);
            memberRepo.findById(1, new ObjectCallback<Member>() {
                @Override
                public void onSuccess(Member member) {
                    System.out.println("Found !");
                }

                public void onError(Throwable t) {
                    System.out.println("Fail");
                }
            });
        }
    });

The thing is that when I execute findById method on localhost:3000/explorer from loopback, it returns the right result and no error at all.

The problem only appears when on Android. I use the strongloop library provided by loopback which use a UserRepository class that contains login, logout, find,.. methods. So they should not be any error coming from the method itself. Which lead me to the actual problem, I really can't figure out where it is from ?


Solution

  • So after a few days of trying everything, I just gave up on strongloop and tried using Retrofit2. Turns out everything works perfectly now.

    Thanks again @Signo for you time! Quite a frustrating ending, but I think as you said, it was probably not provided the right request and I guess the fact that it was not mantained anymore just finished me off.