Why model service still using fetchAll?

Dear admin

According to Controllers

controller code sample:

 if (ctx.query._q) {
      entities = await strapi.services.restaurant.search(ctx.query);
    } else {
      entities = await strapi.services.restaurant.find(ctx.query);
    }

I think controller will use two service functions to retrieve models. one is search the other is find.

But I found the function fetchAll will be executed

my service code:

module.exports = {

  fetchAll(params) {
    strapi.log.info(new Date().toLocaleString(), '---', 'Custom service fetchAll()');
    return null;
  },

  find(params) {
    strapi.log.info(new Date().toLocaleString(), '---', 'Custom service find()');
    return null;
  },

  search(params) {
    strapi.log.info(new Date().toLocaleString(), '---', 'Custom service search()');
    return null;
  }

};

when access http://ibv.com:1339/models, the logs in console:

My question is why model service is still using fetchAll?

Because I have many custom logic in fetchAll function(a legacy strapi application). If I want migrate the legacy application from 3.0.alpha.23 to 3.6.2, do I need implement fetchAll function’s logic in “find” function or I can use fetchAll as before? may I know the best practice?

fetchAll was the deprecated name and you should be using find.

To be completely honest, it may be easier for you to start a fresh project then to actually do the migration steps from the Alpha.

Thank you for your reply :slight_smile:

yes, I started a fresh application, and planning copy/re-implement custom logic at the new fresh application. That’s why I think this issue is weird.

Also would you please help guide how to set default value for strapi 3.6.2?

Or best practice for set a default value? Because we have other legacy applications need all fields from strapi model, if fields not exist or null, other applications will be broken.

I’m not sure what your asking, by default fields are null if you don’t send a value?

Hi DMehaffy

My question is can I set the filedName as “” at the response body?
For example, if I use 3.0.0-alpha.23 , I have model named Book, with two fileds named “name” and “author”, the filed in Book.settings.json looks like this:

"name": {
  "default": "",
  "type": "string"
},
"author": {
  "default": "",
  "type": "string"
}

If I only input author’s value then call /books , I will get the response like below, the field “author” in the response body with value as “”

 [{
  "id":"60ab51794c217efc03e542fc",
   "name": "xxxx"
   "author":""
 }]

But when i use strapi 3.6.2, I will get the response body like this, the field “author” is not in the response body.

 [{
  "id":"60ab51794c217efc03e542fc",
   "name": "xxxx"
 }]

My question is can i put the “author” in the response body by update something in strapi admin?