I'm a newbie to rails, and I have researched a whole day. I think my problem is easy.
There is a table questions_tags_relation, it has two columns(no id):
columns:
question_id -> string
tag_id -> string
And I have a hash:
record = {:question_id=>'111111', :tag_id=>'22222'}
And there is no model 'QuestionsTags', and I don't want to create one.
Now I can get the ActiveRecord::Base.connection
, but how to insert the hash to table using simple code? I hope these is a save
method:
ActiveRecord::Base.connection.save 'questions_tags', record
Is there such a method?
UPDATE
I'm asking this question because I met some problems when I saved data to the database by using ActiveRecord models. Maybe using connection
directly will be simpler. Some of the tables are join
tables, they don't have a primary key, that's why there is no id
in my example. I hope there is a simple way to save a hash to a table, but I can't find it. Thanks, friends