I have two tables:
1.advertiser_accounts
create table if not exists advertiser_accounts (
advertiser_id int(11) not null,
deal_type_id int(11) not null,
primary key (advertiser_id),
CONSTRAINT account_advertiser_refs FOREIGN KEY (advertiser_id) REFERENCES advertisers (ap_advertiser_id ),
CONSTRAINT deal_types_refs FOREIGN KEY (deal_type_id) REFERENCES deal_types (id)
);
2. advertisers
Advertiser(id: integer, ap_advertiser_id: integer)
In Model :
AdvertiserAccount
class AdvertiserAccount < ActiveRecord::Base
belong_to :advertiser
end
Advertiser
class Advertiser < ActiveRecord::Base
has_one :advertiser_account
end
I want to map advertiser_id in advertiser_accounts with ap_advertiser_id in advertiser table
On Console : AdvertiserAccount.first.advertiser
AdvertiserAccount Load (0.2ms) SELECT
advertiser_accounts
.* FROMadvertiser_accounts
ORDER BYadvertiser_accounts
.advertiser_id
ASC LIMIT 1 Advertiser Load (0.2ms) SELECTadvertisers
.* FROMadvertisers
WHEREadvertisers
.id
= 153371 LIMIT 1
I am getting nil as a result
But,i want query like this:
AdvertiserAccount Load (0.2ms) SELECT
advertiser_accounts
.* FROMadvertiser_accounts
ORDER BYadvertiser_accounts
.advertiser_id
ASC LIMIT 1 Advertiser Load (0.2ms) SELECTadvertisers
.* FROMadvertisers
WHEREadvertisers
.ap_advertiser_id
= 153371 LIMIT 1