4

I'm building an integration software between two different systems. I have Clients in a database, and Groups in another. One Client can be in multiple groups, and one group can have multiple clients. So, I created an intermediate table named as clients_groups to represent this relation.

My models are so:

DB1 = Sequel.connect(adapter: 'postgresql'...)
DB2 = Sequel.connect(adapter: 'tinytds'...)

class Client < Sequel::Model
  set_dataset DB1[:clients]

  many_to_many :groups, left_ley: :client_id, right_key: :group_id, join_table: :clients_groups, left_primary_key_column: :id
end

class Group < Sequel::Model
  set_dataset DB2[:groups]

  many_to_many :clients, left_ley: :group_id, right_key: :client_id, join_table: :clients_groups, right_primary_key_column: :id
end

This statement works:

Client.last.groups

While this throws an error:

Group.last.clients # => Sequel::DatabaseError: TinyTds::Error: Invalid object name 'CLIENTS_GROUPS'

What am I doing wrong?

Pedro Vinícius
  • 476
  • 6
  • 13
  • I am assuming client_groups exists only in DB1? – engineersmnky Apr 12 '17 at 22:18
  • Yes @engineersmnky, exactly! My intention is relate the data in both databases through clients_groups in DB 1. – Pedro Vinícius Apr 12 '17 at 23:04
  • Not sure never tried cross database query with different Sql databases but I think either postgres handles this better than tiny tds or you need the join table in both databases. Like I said never tried it I would more likely migrate the data into the preferred database and repoint – engineersmnky Apr 12 '17 at 23:07

0 Answers0