Hi, Jeremy.

Apologies for missing that block in the documentation - I will have a read 
over it now and try your suggestions below.

Thanks for the swift response.

J

On Tuesday, December 11, 2012 12:47:24 AM UTC, Jeremy Evans wrote:
>
> On Monday, December 10, 2012 4:17:23 PM UTC-8, Jeremy Botha wrote:
>>
>> 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
>>
>
> As explained in the "Differences Between many_to_one and one_to_one" 
> section in the Association Basics guide (
> http://sequel.rubyforge.org/rdoc/files/doc/association_basics_rdoc.html), 
> you need to use many_to_one on the side with the foreign key.  You may also 
> need to specify the class manually, since you are using Contacts_Cstm 
> instead of ContactsCstm as the model name.  You should be using a singular 
> association name for both associations.  You probably also need to specify 
> the key manually as well.
>
>   class Contact < Sequel::Model
>     one_to_one :contact_cstm, :key=>:id_c, :class=>:Contact_Cstm
>   end
>
>   class Contact_Cstm < Sequel::Model
>     many_to_one :contact, :key=>:id_c
>   end
>
> Also, you listed your schema with uppercase names, but Sequel is not going 
> to automatically modify your identifiers on MySQL or SQLite, and it quotes 
> identifiers by default.  That means if you get the case of your identifiers 
> wrong, your queries will not work.  You can set identifier input/output 
> methods to automatically modify your identifiers if you want.
>
> If that doesn't work, please reply.  You should probably be testing with 
> an SQL log (DB.loggers << Logger.new($stdout)) so you can see what queries 
> Sequel is issuing to the database.  Be sure to include an SQL log in 
> addition to your code and backtrace if you are still having problems.
>
> Thanks,
> 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/-/ainOpk2jThQJ.
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