rails YAML: NOT NULL constraint failed in joining table -


rails 4.2 have set role model , permission model relate many-to-many each other through model rolespermission use has_many :through relate models.

rolespermission has table name of permissions_roles because of rails convention renamed roles_permissions migration, , put in model class:

self.table_name = "permissions_roles" 

i set fixtures testing

in roles.yml have

admin:   name: admin   permissions: create_user 

and in permissions.yml have

create_user:   name: create_user   description: create new user  edit_user:   name: edit_user   description: edit user details  view_all_users:   name: view_all_users   description: view users 

now when run rake test every test gets error:

activerecord::statementinvalid:      activerecord::statementinvalid:  sqlite3::constraintexception: not null constraint failed: permissions_roles.created_at: insert "permissions_roles" ("role_id", "permission_id") values (135138680, 204622624) 

when remove permission admin role in yaml error goes away.

what's going on?

edit

the joining table looks in schema:

create_table "permissions_roles", force: :cascade |t|   t.integer  "role_id"   t.integer  "permission_id"   t.datetime "created_at",    null: false   t.datetime "updated_at",    null: false end 

i've gradually reached conclusion it's not possible want in way i'm trying it.

i see in rails fixtures can't take advantage of relationships in activerecord use :through label

firstly evidenced fact assumes name joining table, name have if has_and_belongs_to_many relationship seen in another question asked, , secondly this question shows assumes joining table has no created_at column, case if relationship has_and_belongs_to_many.

since rails fixtures don't support convenience syntax when relationship uses :through must either put relationship fixtures in roles_permissions.yml file or must simplify relationship in models using has_and_belongs_to_many.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -