Skip to content
Advertisement

Tag: polymorphic-associations

Polymorphic association query multiple JOIN as separate columns

I’m trying to extract a query that needs to access a polymorphic association table in SQL twice (I need to JOIN it on both ‘types’) Here is the structure for the SQL tables. I want to query each individual answer from the ‘Answer’ table, inner join with ‘User’ table on User.id == Answer.user_id, and inner join with ‘UserGroup’ table to

SQL Conditional / Case Joining / Polymorphic Associations?

I’m trying to implement something similar to Ruby on Rails’ polymorphic relationships. I have the following three tables : Events Users Organisations An event can be owner by either a user or an organisation, so my Events table includes the columns: owner_type and owner_id. I can easily list all events that belong to either users or organisations through an inner

Advertisement