I'm attempting to use jugglingdb (and the mysql adapter) to grab a list of Patients. Our schema is setup so that a Patient must be a User, but a User does not have to be a Patient. This means a Patient has a userId, and the User table holds the name of the patient.
Patient
id
userId
User
id
givenName
familyName
middleInitial
When the initial pages were created, we simply used Patient.all
to grab the results, and patient.user(...
to grab the user object/username. This is fine for a small amount of records, but not for thousands of records.
How do I grab a list of Users, only if their id is referenced in the Patient table? Example mysql query:
SELECT * FROM User WHERE id IN (SELECT id FROM Patient) AND familyName LIKE '%doe%';
I've been browsing the jugglingdb-mysql adapter for a bit now and haven't found an ideal solution, otherwise, this question is the only other solution I've found so far.
Another alternative/query I could use is creating an inner join between Patient and User and then filter the results:
SELECT Patient.id
,User.familyName
FROM Patient
INNER JOIN User ON Patient.userId = User.id
WHERE User.familyName LIKE '%doe%';
But again, I haven't found a solution to joins either using jugglingdb.