I want to limit the Patient models available based on some other table relationships. It’s a bit complicated, and I’m prepared to use SQL to do it - but where do I do it?
Based on the User logged in, they should only see Patients that are active in Studies of which the User is a managing member.
User->Group->Study->Patient
I can handle the relations, but I don’t understand where to start limiting in the actionAdmin…
Hmm…I tried the second method, but it’s not doing anything. its like it’s not even there. My relation is a multiple though, its an array, maybe that’s causing the problem? How can I apply if it’s a multiple relation?
What was your code? Did you do something like this?
'condition'=>'relation2.relation3.Attribute=:att'
You can also write out the SQL (i.e. something like INNER JOIN statement or whatever suits your needs) if the Join is very complex. I tend to keep to using AR though as it is pretty robust.
The example I gave above is from an actual working app. I can probably dig up a better example this weekend of something I have done that is a lot more complex.
Just in case you haven’t been looking at this: Relational Active Record