A course has many lessons and a lesson has many topics.
A topic can have a recipe or vice versa, a recipe has many topics
(optional).
I need to come up with the most efficient way of querying the database
to find those topics belonging to a course (via lessons of course) which
have a recipe (in other words recipe_id is not null for this topic
record).
A course has many lessons and a lesson has many topics.
A topic can have a recipe or vice versa, a recipe has many topics
(optional).
I need to come up with the most efficient way of querying the database
to find those topics belonging to a course (via lessons of course) which
have a recipe (in other words recipe_id is not null for this topic
record).
What is most efficient, depends on whether you want to display only the
topics or you also want to display data from the course model, say
courseās
name etc.
As a hint, look for the difference between include and joins while doing
queries using associations.
Then, come up with your query, post it here and then ask if it is the
best
way to do it, depending on your situation.