Jeremy-
On Oct 23, 2012, at 12:03 PM, Jeremy Evans <[email protected]> wrote: > On Monday, October 22, 2012 5:30:59 PM UTC-7, GregD wrote: > All, > > Something possible broken with one_to_one. I have an older rails project > that I just updated using bundle and I'm getting this: > > In the future, please include an SQL log along with the backtrace, as it > makes it easier to diagnose the cause of the issue. > > Sequel::Error: Record not found > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1534:in > `_refresh' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/associations.rb:1509:in > `_refresh' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1609:in > `_save_refresh' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1596:in > `_save' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1233:in > `block (2 levels) in save' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1701:in > `block in checked_transaction' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/database/query.rb:323:in > `_transaction' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/database/query.rb:285:in > `block in transaction' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/database/connecting.rb:229:in > `block in synchronize' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/connection_pool/threaded.rb:105:in > `hold' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/database/connecting.rb:229:in > `synchronize' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/database/query.rb:278:in > `transaction' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1701:in > `checked_transaction' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1233:in > `block in save' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1692:in > `checked_save_failure' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:1233:in > `save' > from > /Users/gregd/.rvm/gems/ruby-1.9.3-p286@euchre/gems/sequel-3.40.0/lib/sequel/model/base.rb:163:in > `create' > from (irb):4 > > This backtrace indicates that after inserting the record, Sequel cannot > select the row to get the current values of the fields. That can be caused > by insert not returning the correct primary key, and possibly other things. > I'm not sure which line in the code posted below caused this backtrace, and > without an SQL log, it's pretty hard to diagnose what the underlying cause is. It looks like after the insert the key returned is not found in a followup select. It is trying to do a select on id 1. The table is still empty for some reason. et = Tournament.first TournamentConfiguration.create(:tournament => et) (0.031481s) SELECT * FROM `tournaments` LIMIT 1 (0.000198s) SELECT sqlite_version() LIMIT 1 (0.000074s) BEGIN (0.001818s) INSERT INTO `tournament_configurations` (`tournament_id`) VALUES (1) (0.000181s) SELECT * FROM `tournament_configurations` WHERE (`id` = 1) LIMIT 1 (0.000409s) ROLLBACK et = Tournament.first et.configuration=TournamentConfiguration.create (0.003128s) SELECT * FROM `tournaments` LIMIT 1 (0.000220s) SELECT sqlite_version() LIMIT 1 (0.000082s) BEGIN (0.000549s) INSERT INTO `tournament_configurations` DEFAULT VALUES (0.000221s) SELECT * FROM `tournament_configurations` WHERE (`id` = 1) LIMIT 1 (0.000548s) ROLLBACK et = Tournament.first tc = TournamentConfiguration.new tc.tournament = et tc.save 0.003310s) SELECT * FROM `tournaments` LIMIT 1 (0.000629s) SELECT sqlite_version() LIMIT 1 (0.000091s) BEGIN (0.000576s) INSERT INTO `tournament_configurations` (`tournament_id`) VALUES (1) (0.000229s) SELECT * FROM `tournament_configurations` WHERE (`id` = 1) LIMIT 1 (0.000573s) ROLLBACK > > This occurs when I the code is trying to assign a configuration to a > tournament. > > class Tournament < Sequel::Model > one_to_one :configuration, :class => TournamentConfiguration > end > > class TournamentConfiguration < Sequel::Model > many_to_one :tournament > end > > Tournament.first.configuration = TournamentConfiguration.create > > It seems I can not create a TournamentConfiguration. I even tried: > > TournamentConfiguration.create(:tournament => Tournament.first) > > It's better to use many_to_one setters instead of one_to_one setters, > especially for new records (since one_to_one setters cause saves), but both > of the code lines you posted appear to be valid. > > Any help? Am I doing something wrong? Is one_to_one not supported anymore > and should I just use one_to_many for this? > > one_to_one is supported and works fine, there is probably something special > about your environment that is causing it to fail. If you could produce a > self-contained example displaying the error, that would be best, but even > just an SQL log should make it easier to diagnose the cause. It looks like something in the environment. It looks like the last time I had it working Sequel was at 3.23. I tried going back, but talentbox-sequel-rails would also need to be rolled back to an older version and then I'm sure this will cascade to other gems. Worse comes to worse, I could roll those attributes up to the parent record. I had the configuration in a separate one_to_one record so I could marshall the configuration data in and out of a text field as a ruby object. This way I have that data in a simple Sequel object. I tried commenting out all the marshalling and just kept the Sequel association stuff and it still did not work. That is when I emailed the group. Would the Gemfile help? Could it be something in the rails config dir that may have changed. It really looks like the record is never really inserted. Thanks, -GregD -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
