mysql - Rails refuses to insert one field into the database -
basically grab id of element table , insert another.
vuln_id = activerecord::base.connection.execute("select blah ...") pid = vuln_id.first puts "==============================" puts pid # echos id puts "==============================" if pid.empty? puts "pid empty" end rd = report.new(:plugin_id => pid, :report_id => report_id) rd.save()
in rails console, when
report.dbaction(params)
it runs model , here output
(0.3ms) select statement..... ============================== 186 ============================== (3.0ms) begin sql (0.3ms) insert `report_data` (`created_at`, `report_id`, `updated_at`) values ('2013-07-10 22:03:59', 6, '2013-07-10 22:03:59') (33.9ms) commit
it inserts report_id
doesnt insert pid
value database, though exists. why this?
quick edit: plugin_id exists in table. triple checked.
here rest of model file looks like
class report < activerecord::base belongs_to :site has_many :plugins
you're getting first result database query in line 1 execute
returns array of arrays, believe, contains columns selected. want: pid = vuln_id.first[0]
or (or pid = vuln_id[0][0]
or pid = vuln_id.first.first
).
you should verify query returned @ entire line might like:
pid = vuln_id.first.first if vuln_id , vuln_id.count > 0
Comments
Post a Comment