I would like to filter by a keyword in a table which doesn't contain actual data by itself but only foreign keys to other tables. The problem is that I can't just write Incident::where(...) because that would filter by the foreign keys ids and not the data they contain. By the way, the column by which I would like to filter is always called "name" in the referenced table.
To clarify: I have a table 'incidents' with foreign keys like 'contact_method_id' and 'requested_by_id' and I would like to filter the rows of the incidents table by a keyword like 'john' and instead of comparing 'john' to the 'contact_method_id' or 'requested_by_id' I would like to compare it both to 'contact_methods.name' and 'users.name'.
Does anyone know if this is possible? Thanks in advance!