In a Rails v4 has_many association how can you have a computed primary key column -


i have rails model has hstore (using hstore_accessor gem). when set primary key on has_many association hstore field generated sql searching null (postgres).

so there way define custom method compute primary key of association?

if do:

has_many :email_blocks, lambda { |cm| where(email_address: cm.email_address) },   foreign_key: :email_address 

then can of way there sql:

select "email_blocks".* "email_blocks" "email_blocks"."email_address" = '950b5f7b-9388-45f4-9c42-42e18337b09c' , "email_blocks"."email_address" = 'me@example.com' 

but first clause checking primary key of relation unnecessary since sql return want:

select "email_blocks".* "email_blocks" "email_blocks"."email_address" = 'me@example.com' 


Comments