Good evening all.

I'm currently in the process of evaluating Sequel as a replacement for AR 
in my company's codebase.  Our platform is JRuby and we've had some 
difficulties related to AR, garbage collection and connection pooling which 
I won't go into here.

I've run into an issue which relates to trying to create Sequel models 
mapping an existing legacy MySQL schema, and I'm hoping someone here can 
point me in the right direction with examples or a link to relevant 
sections in the Sequel docs.  I've spent quite a bit of time in the 
ActiveRecord and Associations pages but haven't found an answer.  

A simplified version of the schema is as follows:
I have two tables, CONTACTS and CONTACTS_CSTM.  CONTACTS_CSTM belongs to an 
external application, but some of its data is used throughout our system. 
 CONTACTS.ID maps one to one onto CONTACTS_CSTM.ID_C

The Sequel models for this association should be:

class Contact < Sequel::Model
  one_to_one :contacts_cstm
end

class Contacts_Cstm < Sequel::Model
  one_to_one :contacts
end

However, Sequel freaks out when I try to refer to contact.contacts_cstm, 
and the simple Sinatra / SQLite3 app that I am testing with logs the 
following errors:

23:39:39,435 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) tried to 
create Proc object without a block
23:39:39,437 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
org/jruby/RubyModule.java:1513:in `define_method'
23:39:39,437 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:1250:in
 
`generate_method'
23:39:39,437 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:1259:in
 
`compile!'
     <Sinatra + Rack spam snipped>
23:39:39,440 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
org/jruby/RubyArray.java:1615:in `each'
23:39:39,440 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/database/logging.rb:70:in
 
`log_each'
23:39:39,440 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/database/logging.rb:22:in
 
`log_exception'
23:39:39,440 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/database/logging.rb:39:in
 
`log_yield'
23:39:39,441 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/adapters/jdbc.rb:257:in
 
`execute'
23:39:39,441 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/adapters/jdbc.rb:561:in
 
`statement'
23:39:39,441 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/adapters/jdbc.rb:255:in
 
`execute'
23:39:39,441 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/connection_pool/threaded.rb:104:in
 
`hold'
23:39:39,441 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/database/connecting.rb:240:in
 
`synchronize'
23:39:39,442 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/adapters/jdbc.rb:254:in
 
`execute'
23:39:39,442 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/dataset/actions.rb:778:in
 
`execute'
23:39:39,442 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/adapters/jdbc.rb:630:in
 
`fetch_rows'
23:39:39,442 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/dataset/actions.rb:152:in
 
`each'
23:39:39,442 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/dataset/actions.rb:55:in
 
`all'
23:39:39,443 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/model/associations.rb:1489:in
 
`_load_associated_object_array'
23:39:39,443 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/model/associations.rb:1483:in
 
`_load_associated_object'
23:39:39,443 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/model/associations.rb:1499:in
 
`_load_associated_objects'
23:39:39,443 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/model/associations.rb:1577:in
 
`load_associated_objects'
23:39:39,444 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Java/torquebox-2.1.2/jruby/lib/ruby/gems/1.8/gems/sequel-3.42.0/lib/sequel/model/associations.rb:1109:in
 
`contacts_cstm'
23:39:39,444 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
org/jruby/RubyProc.java:270:in `call'
23:39:39,444 INFO  [stdout] (http-127.0.0.1/127.0.0.1:8080-1) 
C:/Users/Jeremy 
Botha/RubymineProjects/sequel-sinatra/app/web/contact_web_handler.rb:15:in 
`HEAD /contact/id/:id'

>From this I assume that there is some sort of convention going on inside 
Sequel and that the legacy table name is not what Sequel either expects or 
supports.

If I change the schema to

CONTACTS, CONTACT_CSTMS

and the models to 

class Contact < Sequel::Model
  one_to_one :contact_cstm
end

class Contact_Cstm < Sequel::Model
  one_to_one :contacts
end 

then everything works perfectly and I am able to use the 
contact.contact_cstm association.  Unfortunately, given that this database 
schema is used in the proverbial Big Ball of Mud architecture there is no 
way for me to change it as part of my evaluation work.  Is there a way to 
make the existing legacy schema names function in the Sequel associations 
above, or will I have to resort to making a view of the existing table?

thanks, and apologies in advance if I'm missing something obvious.  It's 
midnight and this has had me stumped all day :-)
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/XmzoMVJG_AAJ.
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.

Reply via email to