Relation manager pulls wrong data
I have built a demo EHR system around medical records- I may not have architectured this correctly but i want to have appointments and prescriptions link so when a patient gets prescribed something its linked to an appointment, doctor, patient. i created PrescriptionsRelationManager which when i added to my ViewAppointment page it loads information about appointments rather than prescriptions?
10 Replies
It looks good. You create method also says prescription so where you are getting new appintment from I am unsure.
Check what your relationship 'prescriptions' is.
you are correct i had the wrong model class in my relation on the Appointment Model
@toeknee another question, how do i overwride the relation manager query to ignore the appointment_id? yes prescriptions have an appointment_id in the table but i want to see all the patients prescriptions rather than just ones for that appointment, but if one is added through the relationmanager it should be saved with the appointment id
add an additional where to the query imho..... add a new relationship
all_prescriptions
See:
https://filamentphp.com/docs/2.x/admin/resources/relation-managers#deleting-records
There is the getTableQuery method, just add a where('id', '>', 0) or modify it and remove the where record id.
@toeknee i tried this but i'm in filament 3 and i think adding the method is deprecated
On the $table instance in the source
->modifyQueryUsing(fn(Builder $query) => $query->where('appointment_id', '>', 1))
@toeknee i dont think you can overwrite the where clauses from the relationmanager- just add to them?
I am fairly sure you can, I haven't checked though.
But adding
->modifyQueryUsing(fn(Builder $query) => $query->where('appointment_id', '>', 1))
To the relation manager table means it will find all above the id of 1 which basically means the id doesn't matter.
thanks for your responses, this is what i have added
and checked the debug bar you can see the query is
so it just appends where clauses on to the end of the existing generated query
That limits it to the appointment_id still.... but also null values change it to the above.
I beleive the above is then right
thanks for that but updating it to your code has the same issue, the query ends up similar
@toeknee i managed to get this working- its disgusting but works: