This is SQL, I need SQLAlchemy to generate through my ORM.
SELECT
*
FROM
notes
WHERE
notes.student_id == {student_id}
OR
notes.student_id IN (
SELECT
*
FROM
peers
WHERE
peers.student_id == {student_id}
AND
peers.date_peer_saved >= notes.date_note_saved
)
SQL not verified. I just wrote it to demonstrate that I need SQLAlchemy.
Basically, a registered student should see a list of saved ones notes. However, the student should only see those that were sent by themselves or those that were sent by one of their peers. But only those peers whom they "were friends" after the note was saved.
This way, the student will not see notes sent by another student before they become peers.
I am having trouble getting this to run in SQLAlchemy ORM. Any help?