How to use joins to get this data
property
• id
• address
properties_to_users
• id
• user_id
• property_id
• role_name
user
• id
• name
How do I get the result of a query that shows the properties associated with a user with the users roles. I only want to show the property once.
This is for an authenticated user, so the input is the user_id.
It should look like this:
user_properties = [
{
id: 001
address: '1234 main st'
user_roles: [ 'editor','admin','common' ]
},
{
id: 004
address: '59 Halifax Rd'
user_roles: [ 'editor','common' ]
},
{
id: 008
address: '50 MLK Jr. Blvd'
user_roles: [ 'common','admin' ]
}
]
I can figure out how to join and show the property multiple times, with the associated role. But, I cannot figure out how to only show the property once, with the associated roles.
Other
4 replies