{"action":"created","issue":{"url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex/issues/150","repository_url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex","labels_url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex/issues/150/labels{/name}","comments_url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex/issues/150/comments","events_url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex/issues/150/events","html_url":"https://github.com/feathersjs-ecosystem/feathers-knex/issues/150","id":308281053,"number":150,"title":"Can't find relation if table name != service name?","user":{"login":"kodayashi","id":916855,"avatar_url":"https://avatars1.githubusercontent.com/u/916855?v=4","gravatar_id":"","url":"https://api.github.com/users/kodayashi","html_url":"https://github.com/kodayashi","followers_url":"https://api.github.com/users/kodayashi/followers","following_url":"https://api.github.com/users/kodayashi/following{/other_user}","gists_url":"https://api.github.com/users/kodayashi/gists{/gist_id}","starred_url":"https://api.github.com/users/kodayashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kodayashi/subscriptions","organizations_url":"https://api.github.com/users/kodayashi/orgs","repos_url":"https://api.github.com/users/kodayashi/repos","events_url":"https://api.github.com/users/kodayashi/events{/privacy}","received_events_url":"https://api.github.com/users/kodayashi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-24T17:13:37Z","updated_at":"2018-03-26T20:52:40Z","closed_at":null,"author_association":"NONE","body":"### Steps to reproduce\r\n\r\n(First please check that this issue is not already solved as [described\r\nhere](https://github.com/feathersjs/feathers/blob/master/.github/contributing.md#report-a-bug))\r\n\r\n- [X] Tell us what broke. The more detailed the better.\r\n\r\nI have a service called \"user-roles\" and a model called \"user-roles\" that is tied to a table called \"user_roles\". When I do `app.service('user-roles').find({})` I get \"error:  error: relation \"user-roles\" does not exist\".\r\n\r\nIf the table name isn't identical to the service name will queries not work? Does there need to be an explicit mapping? All of my services that are a single word are working fine.\r\n\r\nI created my service and model with the feathers cli, so it should be wired up properly:\r\n\r\nuser-roles.service.js:\r\n\r\nconst createService = require('feathers-knex');\r\nconst createModel = require('../../models/user-roles.model');\r\nconst hooks = require('./user-roles.hooks');\r\n\r\nmodule.exports = function (app) {\r\n  const Model = createModel(app);\r\n  const paginate = app.get('paginate');\r\n\r\n  const options = {\r\n    name: 'user-roles',\r\n    Model,\r\n    paginate\r\n  };\r\n\r\n  // Initialize our service with any options it requires\r\n  app.use('/user-roles', createService(options));\r\n\r\n  // Get our initialized service so that we can register hooks and filters\r\n  const service = app.service('user-roles');\r\n\r\n  service.hooks(hooks);\r\n};\r\n\r\nuser-roles.model.js:\r\n\r\n/* eslint-disable no-console */\r\n\r\n// user-roles-model.js - A KnexJS\r\n//\r\n// See http://knexjs.org/\r\n// for more of what you can do here.\r\nmodule.exports = function (app) {\r\n  const db = app.get('knexClient');\r\n  const tableName = 'user_roles';\r\n  db.schema.hasTable(tableName).then(exists => {\r\n    if(!exists) {\r\n      db.schema.createTable(tableName, table => {\r\n        table.increments('id').primary();\r\n        table.string('name').unique().notNull();\r\n        table.boolean('is_internal').notNull();\r\n        table.timestamps(true, true);\r\n      })\r\n        .then(() => console.log(`Created ${tableName} table`))\r\n        .catch(e => console.error(`Error creating ${tableName} table`, e));\r\n    }\r\n  });\r\n\r\n\r\n  return db;\r\n};\r\n\r\n- [X] If you can, please create a simple example that reproduces the issue and link to a gist, jsbin, repo, etc.\r\n\r\n### Expected behavior\r\nTell us what should happen\r\n\r\nGiven the files above, I would think knex could query the user_roles table properly.\r\n\r\n### Actual behavior\r\nTell us what happens instead\r\n\r\nIt looks like since the service name is 'user-roles', knex is trying to query a relation called 'user-roles' instead of the one defined in the model ('user_roles').\r\n\r\n### System configuration\r\n\r\nTell us about the applicable parts of your setup.\r\n\r\n**Module versions** (especially the part that's not working):\r\n\r\n  \"dependencies\": {\r\n    \"@feathersjs/authentication\": \"^2.1.2\",\r\n    \"@feathersjs/authentication-jwt\": \"^2.0.0\",\r\n    \"@feathersjs/authentication-local\": \"^1.1.0\",\r\n    \"@feathersjs/configuration\": \"^1.0.2\",\r\n    \"@feathersjs/errors\": \"^3.3.0\",\r\n    \"@feathersjs/express\": \"^1.2.0\",\r\n    \"@feathersjs/feathers\": \"^3.1.3\",\r\n    \"@feathersjs/socketio\": \"^3.2.0\",\r\n    \"compression\": \"^1.7.1\",\r\n    \"cors\": \"^2.8.4\",\r\n    \"feathers-knex\": \"^3.0.2\",\r\n    \"helmet\": \"^3.11.0\",\r\n    \"knex\": \"^0.14.3\",\r\n    \"pg\": \"^7.4.1\",\r\n    \"serve-favicon\": \"^2.4.5\",\r\n    \"winston\": \"^2.4.0\"\r\n  },\r\n  \"devDependencies\": {\r\n    \"eslint\": \"^4.18.0\",\r\n    \"mocha\": \"^5.0.1\",\r\n    \"request\": \"^2.83.0\",\r\n    \"request-promise\": \"^4.2.2\"\r\n  }\r\n\r\n**NodeJS version**:\r\n\r\n**Operating System**:\r\n\r\n**Browser Version**:\r\n\r\n**React Native Version**:\r\n\r\n**Module Loader**:"},"comment":{"url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex/issues/comments/376307789","html_url":"https://github.com/feathersjs-ecosystem/feathers-knex/issues/150#issuecomment-376307789","issue_url":"https://api.github.com/repos/feathersjs-ecosystem/feathers-knex/issues/150","id":376307789,"user":{"login":"kodayashi","id":916855,"avatar_url":"https://avatars1.githubusercontent.com/u/916855?v=4","gravatar_id":"","url":"https://api.github.com/users/kodayashi","html_url":"https://github.com/kodayashi","followers_url":"https://api.github.com/users/kodayashi/followers","following_url":"https://api.github.com/users/kodayashi/following{/other_user}","gists_url":"https://api.github.com/users/kodayashi/gists{/gist_id}","starred_url":"https://api.github.com/users/kodayashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kodayashi/subscriptions","organizations_url":"https://api.github.com/users/kodayashi/orgs","repos_url":"https://api.github.com/users/kodayashi/repos","events_url":"https://api.github.com/users/kodayashi/events{/privacy}","received_events_url":"https://api.github.com/users/kodayashi/received_events","type":"User","site_admin":false},"created_at":"2018-03-26T20:52:40Z","updated_at":"2018-03-26T20:52:40Z","author_association":"NONE","body":"@jerfowler - Yep that was it, thanks!\r\n@daffl - I changed the table name in the model file after generating so I'm not sure there was an issue with the generation. Just didn't realize that option above was for the table's name (thought it was the service name)."}}
{"actor":{"display_login":"kodayashi"}}