relation แบบ has_many :collection บน Oracle Database

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ผมลองเขียน unit test เพื่อทดสอบ has_many relation ครับตามตัวอย่างในหนังสือ

class Order:ActiveRecord:Base
 has_many :line_items
 ..
 ..
class LineItem:ActiveRecord:Base
 belongs_to :order
 ..
 ..

ทำงานได้ปกติดีบน MySql ครับแต่พอเอาไปทดสอบบน Oracle XE มีปัญหาครับเพราะแทนที่ active record จะทำการเอา id จาก order ที่ถูก persistก่อนไปใส่ใน line_item มันกลับไปเอา id ของ order ตัวอื่นจาก order_sequence ครับทำให้ persist ไม่ลงเพราะติด constraint

ไม่ทราบใครช่วยชี้แนะได้บ้างครับ

roof ลองทดสอบบน script/console ดู
(http://slash7.com/articles/2006/12/21/secrets-of-the-rails-console-ninjas)
ดูประกอบกับ log/development.log
เทียบกันระหว่าง mysql กับ oracle

(มันมีวิธีดู sql ใน script/console เหมือนกัน
แต่ผมจดไว้ที่ทำงาน เดี๋ยวพรุ่งนี้ผม post ให้)

roofimon's picture

ขอบคุณครับพี่

$ script/console
>> ActiveRecord::Base.logger = Logger.new(STDOUT)
=> #<Logger:0x2814134 ...>
>> account = Account.find(:first)
  Account Load (0.000346)   SELECT * FROM accounts LIMIT 1
=> #<Account:0x2665478 ...>
>> account.people.create :name => "Jamis Buck"
  Account Columns (0.000271)   SHOW FIELDS FROM accounts
  Person Columns (0.000246)   SHOW FIELDS FROM people
  SQL (0.000093)   BEGIN
  SQL (0.000351)   INSERT INTO people (`account_id`, `name`) VALUES (1, 'Jamis Buck')
  SQL (0.253635)   COMMIT
=> #<Person:0x27cb628 ...>

สั่งเปิด logger บน STDOUT จะได้มองเห็นว่า คำสั่งไหนเกิด sql อะไรบ้าง

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น