habtm question

hi,

i have 2 tables on a external database which i want to integrate in my
rails-app.

class External < ActiveRecord::Base
  establish_connection :extern
end

class Land < External
  set_table_name "landen"
end

class Bestemming < External
  set_table_name "bestemmingen"
end

This works fine:

test = Bestemming.find(:first)

#<Bestemming:0xb701nb3c0 @attributes={"airport_name"=>"Lehigh Valley
Intl Arpt", "landcode"=>"US", "alt_naam"=>"", "bestemming_id"=>"ABE",
"dist_ams"=>"5948.3", "naam_en"=>"Allentown", "naam"=>"Allentown",
"stad_zoeknaam"=>"allentown"}>

test = Land.find(:first)

<Land:0xb7018ad0 @attributes={"landcode"=>"AF", "alt_naam"=>"",
"landafk"=>"AFG", "land_zoeknaam"=>"afghanistan",
"naam_en"=>"Afghanistan", "naam"=>"Afghanistan"}>

Question: How can i realize a relationship between this classes.
Landcode is the foreign_key.

Grtz, remco

Doesn't this work

class Land < External
  has_and_belongs_to_many :bestemmigens
  set_table_name "landen"
end

class Bestemming < External
  has_and_belongs_to_many :landens
  set_table_name "bestemmingen"
end

Adhiraj Rankhambe wrote:

Doesn't this work

class Land < External
  has_and_belongs_to_many :bestemmigens
  set_table_name "landen"
end

class Bestemming < External
  has_and_belongs_to_many :landens
  set_table_name "bestemmingen"
end

Nope...

I have different primary_keys than default..because it is an central
database.

Setup:

class External < ActiveRecord::Base
  establish_connection :extern
end

class Land < External
  has_and_belongs_to_many :bestemming
  set_table_name "landen"
  set_primary_key "landcode"
end

class Bestemming < External
  has_and_belongs_to_many :land
  set_table_name "bestemmingen"
  set_primary_key "bestemming_id"
end

Field | Type | Null | Key | Default | Extra |

ok so what about the join table bestemming_land_join_tables?

Does it have the keys landcode and bestemming_id?