[問題] Datamapper hook?

看板Ruby作者 (Egg)時間16年前 (2008/12/24 22:25), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
環境: Datamapper 0.9.8 這裡面有兩個class: class User include DataMapper::Resource property :id, Serial property :login, String belongs_to :group before :create do throw :halt, false end end class Group include DataMapper::Resource property :id, Serial has n, :users end 然後這是irb裡面的執行 irb(main):001:0> g = Group.create ~ INSERT INTO "groups" DEFAULT VALUES => #<Group id=1> irb(main):002:0> u = User.new(:login => "a", :password=>"1", :password_confirmation=>"1", :group=>g) => #<User id=nil login="a" group_id=1 crypted_password=nil salt=nil> irb(main):003:0> u.save => true irb(main):004:0> u => #<User id=nil login="a" group_id=1 crypted_password="135dcb3fbe621834f065cea764358b6337f03890" salt="686dcc798935df374e38fdb0667746c2d0365e82"> 問題在這裡:明明u就沒有存到database裡面去,可是它卻傳回一個true 是我的hook寫錯了嗎? 還是是別的問題? PS. User是merb-auth的auth物件 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.11.65.12

12/24 22:30, , 1F
你程式不完整
12/24 22:30, 1F

12/24 22:32, , 2F
btw, datamapper 0.9.8 爛掉一堆地方,建議用舊的...
12/24 22:32, 2F
文章代碼(AID): #19KaPovh (Ruby)
文章代碼(AID): #19KaPovh (Ruby)