You have right Jeremy! Thanks for answer, but at this point I have next 
problem. "hash" attribute it's of course something other that the "#hash` 
method on ruby object. The sequel add object#hash value instead of 
attribute hash value. Can I do something or it's impossible and I need to 
rename the column?

W dniu piątek, 23 czerwca 2017 06:30:33 UTC+2 użytkownik Jeremy Evans 
napisał:
>
> On Thursday, June 22, 2017 at 9:19:19 PM UTC-7, Anonymous Testing wrote:
>>
>> Tutaj wprowadź kod...
>>
>> Hello guys!
>> I have very weird problem with many to many associations. Before any info 
>> I must notice that I can't change table structure cause I rewriting app and 
>> DB must looks the same.
>>
>> First model
>> class User < Sequel::Model
>>   many_to_many :devices, left_key: :token, right_key: :user, join_table: 
>> :users_devices
>> end
>>
>> Second model
>> class Device < Sequel::Model
>>   many_to_many :users, left_key: :hash, right_key: :device, join_table: 
>> :users_devices
>> end
>>
>> Joining class
>> class UsersDevice < Sequel::Model
>>   many_to_one :user
>>   many_to_one :device
>> end
>>
>> Migration
>> create_table :devices do
>>   primary_key :id, type: Integer
>>   column :device_id, String
>>   column :hash, String
>> end
>>
>> create_table :users do
>>   primary_key :id, type: Integer
>>   column :token, String
>> end
>>
>> create_table :users_devices do
>>   primary_key :id, type: Integer
>>   column :device, String, null: false
>>   column :user, String, null: false
>> end
>>
>>
>> When I try to get all users from device I see in logs:
>>   Sequel::Postgres::Database (2.2ms)  SELECT "users".* FROM "users" INNER 
>> JOIN "users_devices" ON ("users_devices"."device" = "users"."id") WHERE 
>> ("users_devices"."hash" = 142)
>>
>> Of course, it doesn't work cause I try map device with id instead of 
>> device with hash...
>> I do something wrong?
>>
>
>
> You probably want something like:
>
>   Device.many_to_many :users, left_primary_key: :hash, left_key: :device, 
> right_key: :user, :right_primary_key :token, join_table: :users_devices
>
> The documentation does explain what each option does, you should probably 
> review it: 
> http://sequel.jeremyevans.net/rdoc/files/doc/association_basics_rdoc.html#label-3Aleft_key+-5Bmany_to_many-2C+one_through_one-5D
>
> 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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to