I have a table User_Device with fields username, num_of_years and device (foreign key), table Device with fields id, name, type and many to many relationship on field property, which is the third table Property that has fields id, name, location. I know how to get all the fields from the first 2 tables:
User_Device.objects.select_related('device').all()
I also know how to get all the fields of the many to many table:
Device.property.through.objects.all()
or filter using:
Device.property.through.objects.filter(property=12)
which gives me all the fields of the many to many table alone, which looks like Device_Property with fields device_id, property_id
I have 2 questions:
How do I get all fields of the Device table and the property table like the SQL query would give when you inner join it like:
select d.*,p.* from device_property dp inner join property p on dp.property_id=p.id inner join device d on dp.device_id=d.id
How to inner join all the three tables and get all fields like the result of the query:
select ud.*,d.*,p.* from user_device ud inner join device_property dp on ud.device_id = dp.device_id inner join property p on dp.property_id=p.id inner join device d on dp.device_id=d.id
In conclusion table A has a foreign key field on table B and table B has a many to many relationship with table C (NOT foreign key). How do I get ALL fields of table A, B, C