ruby on rails - ActiveRecord destroy_all throws StatementInvalid -


i using activerecord oracle adapter on ruby on rails. getting statementinvalid exception when trying delete row.

here how table looks : room_user_table

room | user 1010 | 1010 | b 1011 | 1011 | c 1011 | d 

my ruby activerecord class:

class roomusertable < activerecord:base     self.table_name = 'room_user_table' end 

now want delete 2nd row example, issuing

roomusertable.destroy_all(:room => 1010, :user => 'b') 

but throwing activerecord::statementinvalid exception

ocierror: ora-01741: illegal zero-length identifier: delete "room_user_table" "room_user_table"."" = :a1 

any appreciated.

my test_controller.rb

class testcontroller < actioncontroller::base     def test        roomusertable.destroy_all(:room => 1010, :user => 'b')     end end 

your roomusertable doesn't have primary key, causing run query have in question where "room_user_table"."" = ... in turn causing oracle throw wobbly. rails models need have primary keys.

the table looks join table therefore don't need create model or query directly @ all. can use has_and_belongs_to_many relationship between user , room , specify join table.

class room < activerecord::base   has_and_belongs_to_many :users, join_table: :room_user_table end  class user < activerecord::base   has_and_belongs_to_many :rooms, join_table: :room_user_table end 

or similar.

edit - having said have a, b etc in user column, i've no idea table is, problem still same, don't have primary key.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -