简体   繁体   中英

Ransack: finding record without a :has_one assoc

Given a ModelA which has_one ModelB.

What should I write if I want to add a checkbox in the ModelA form to filter the results to only show ModelsA who are NOT associated with ModelB.

I tried:

f.check_box :modelb_null, {}, true, nil

and

f.check_box :modelb_id_null, {}, true, nil

without success.

You do need to call a specific field on the association, not just the model name, and ID makes the most sense as per your second attempt.

I got this working using the blank predicate:

f.check_box :modelb_id_blank, {}, true, nil

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM