I have a Patient model that has_many :admissions. I want to create a scope for the patient model that will return all patients that are currently admitted. A patient is determined to be admitted if any of their admissions has a discharge_time of nil. I can do this easily enough in the app by iterating through the patients and checking each admission but it seems like I should be getting the database to do this. I haven't written a scope like this before. Any suggestions? (I'm using sqlite3 in development and postgresql in production in case some SQL is necessary - I hope it isn't)
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- JavaScript variable scope question: to var, or not
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
You can also do something like this which I think is a little DRYer: