Search code examples
sails.jswaterline

Waterline ORM error: Error: Trying to access a collection string that is not defined


I'm using sails version 0.12 with waterline ORM for generating models. I'm getting this error Error: Trying to access a collection string that is not defined while trying to run sudo sails lift command.

module.exports = {

  attributes: {
    manufacturer_name: {
      type: 'string'
    },
    manufacturer_logo_url: {
      type: 'string'
    },
    manufacturer_archived_status: {
      type: 'boolean'
    },
    manufacturer_tabs: {
      model: 'manufacturer_tabs'
    },
    brands: {
      model: 'brands'
    }
  }
};

Solution

  • In your associations with models the name of the model have to match the exact name of your model, i.e. the file name. Usually your models (file names) should be in JAVA style CamelCase (or PascalCase) notation. So your code should look like this:

    module.exports = {
    
      attributes: {
        manufacturer_name: {
          type: 'string'
        },
        manufacturer_logo_url: {
          type: 'string'
        },
        manufacturer_archived_status: {
          type: 'boolean'
        },
        manufacturer_tabs: {
          model: 'ManufacturerTabs'
        },
        brands: {
          model: 'Brands'
        }
      }
    };
    

    And your associated models should be in files with names ManufacturerTabs.js and Brands.js.

    My advise: avoid using C and system programming style notations as it is not well accepted anymore in modern scripting languages, excluding python. Use camelCase for your javascript code. So consider replacing manufacturer_name with manufacturerName, manufacturer_logo_url with manufacturerLogoUrl, etc. It's your choice though, but hey, it is nice to follow the conventions.