Following naming conventions getting error


#1

When using belongsToMany() with Adonisjs convention I get an error stating that the table profile_role doesn’t exist.

select 
  roles.*, 
  profile_role.role_id as pivot_role_id, 
  profile_role.profile_id as pivot_profile_id 
from roles 
inner join profile_role on roles.id = profile_role.role_id 
where profile_role.profile_id in (1) 

- ER_NO_SUCH_TABLE: Table adonis_development.profile_role'doesn't exist

This error is correct as this table doesn’t exist in my database, however Adonis generated my table name as profile_roles in a migration which is the correct convention, but for some reason belongsToMany() seems to be looking for a table named profile_roles.

Before I file an issue with Adonis or Knexjs I wanted make sure I’m not doing anything wrong here.

P.S.
I’m aware that I can specify a pivot table and using that in the interim.

Thanks!


#2

Your relateModel (the ProfileRole one) should have the table attribute set to the correct one.


#3

Sure. I understand that, but if I’ve created the model with using

adonis make:model ProfileRole // yields profile_roles

then why do I have to specifically set it to profile_role?