Hi guys, I've a problem retrieving values from db.
I have a many to many relation between Archives and Contents. I need to get an archive and all related contents, but only if "contents.published is equal to 1". Here is my code:
The problem is this: if I have only NOT published contents, I want to retrieve the archive and I want the "contents" property to be empty. With that query the entire $archive value is empty.
"Related queries are generated using subqueries, which in combination with get_one() might not give you the result you expect." This sound a bit confusing. Haven't seen anything about this in the docs.
The ORM will always try to construct consistent resultsets.
Which means that if you have 1 parent and 10 children, and you request a limit(5), in a normal join you will only get 5 of the 10 child records back. With ORM, you will still get all 10 children back.
A get_one() is basically a limit(1)->get(), so it will follow this rule.
However, if you use rows_limit() instead of limit(), the limit will be applied to the outer query (the join itself), producing a result you would get when you would have manually written the join.
Just try the two, enable the profiler, and database profiling, and compare the SQL of the two queries produced.