I have these models:
class A < ActiveRecord::Base
has_and_belongs_to_many :Bs
end
class B < ActiveRecord::Base
has_and_belongs_to_many :As
end
class CreateAs < ActiveRecord::Migration
def change
create_table :as do |t|
t.string :name
t.timestamps null: false
end
end
end
class CreateBs < ActiveRecord::Migration
def change
create_table :bs do |t|
t.string :name
t.timestamps null: false
end
end
end
If table 'as' has the following entries:
- "A1"
- "A2"
- "A3"
and table 'bs' has the following entries:
- "B1"
- "B2"
- "B3"
Does table 'as' have a foreign_key of b and vice-versa?
If yes, then how does internal mapping take place in Rails 4? How it will map? And how can I join and display both these tables?