On Sunday, January 12, 2014 11:03:26 AM UTC-8, Christoph Haas wrote: > > Evening… > > I'm on Sequel 4.6.0 and want to use it to build a web application with > Padrino and test it with RSpec. I did not find any public project of > that combination that allowed me to look how others work with it so I'm > advancing slowly with 20 tabs of documentation open in my browser. :) > > At the moment I'm writing tests for my models. And it seems that if I'm > trying to creating an associated record I get this exception: > > -> Sequel::Error: invalid associated object, cannot save > > although I have set "raise_on_save_failure=false" which indeed works > when I'm trying to save invalid model records. > > This is my model: > > class VirtualDomain < Sequel::Model > one_to_many :virtual_users, :key => 'domain_id' > > plugin :validation_helpers > def validate > …some validation > end > end > > class VirtualUser < Sequel::Model > many_to_one :virtual_domain, :key => 'domain_id' > > plugin :validation_helpers > def validate > …some validation > end > end > > I have set this before connecting to my MySQL database: > > Sequel::Model.raise_on_save_failure = false > > Now what I'm trying in my tests (or on the console): > > > domain=VirtualDomain.create(:name=>'example.com') > > domain.add_virtual_user(:email=>'invalid@address', > :password=>'tooshort') > Sequel::Error: invalid associated object, cannot save > > [For some reason I can't even catch that exception from RSpec like > expect(…).to raise_error] > > A valid workaround seems to be: > > > domain=VirtualDomain.create(:name=>'example.com') > > user=VirtualUser.new(:email=>'invalid@address', :password=>'tooshort') > > expect(user).to be_valid > > I have basically no idea of the Sequel core itself. But it seems to me > like the truth might be somewhere here: > > https://github.com/jeremyevans/sequel/blob/dde03831d556570f9c60826f6fdf304febd2e339/lib/sequel/model/associations.rb#L1445 > > Perhaps a simple condition check if raise_on_save_failure is set before > raising that error? > > Any hints? >
Your workaround of creating it manually is the correct way to handle it currently. In terms of handling it inside Sequel, I don't think it should be changed by default, as the backwards compatibility breakage is too high. I suppose we could handle it via an additional plugin. What do other users think of this situation? Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/groups/opt_out.
