I use finder to get resources and a second table;
now the result has around 50 cols and i need only 10.
How can i reduce the query to the needed fields only, please?
SELECT xf_rm_resource., Plan_Plan_1.
FROM xf_rm_resource
LEFT JOIN Plan AS Plan_Plan_1 ON (Plan_Plan_1.resource_id = xf_rm_resource.resource_id)
WHERE (xf_rm_resource.resource_category_id = 1)
ORDER BY xf_rm_resource.title ASC
In short: fetch some resources and left join some data from a second table Plan.
The result in phpMyAdmin looks like it should:
all cols from xf_rm_resource and all fields from table Plan.
But $resources has only the content from ResourceItem.
How can i tell the finder
a) to put all fields to the $result and
b) to fetch only the fields i need
Finally i sit here for hours to find a way to use relations and getters to get a query that doesnt fill my $results.
Why i schould not use just a normal query and be finished in ten minutes?
Relations are their own entity, and the data can be modified directly on it. To get your Plan entity from the ResourceItem you'd use $resources->first()->Plan (you can also use fetchOne on the Finder instance to fetch a single Entity).
XenForo 2 generally always uses full entities when dealing with data.
I dont want to have query for Plan. I need ResourceItems left joined a row from Plan.
And the mysql query is correct
SELECT xf_rm_resource., Plan_Plan_1.
FROM xf_rm_resource
LEFT JOIN Plan AS Plan_Plan_1 ON (Plan_Plan_1.resource_id = xf_rm_resource.resource_id)
WHERE (xf_rm_resource.resource_category_id = 1)
ORDER BY xf_rm_resource.title ASC
but there is nothing from Plan in $resources and alos there is nothing in Plan
That would be because the Plan row corresponding to the relation key couldn't be found. How is the Plan relation defined in the ResourceItem structure? Are you using the correct key?
Yes. If i use the query from above in phpMyAdmin i get everything i want:
all fields from resource and all fields from plan (and resource_id twice times)
resource_id is the primary in both tables.
The query is correct, the result in mysql is correct, but results->Plan is empty and no extra data in results->resourceitem
I tried to make everything like in the wordcount add-on; there is post and a new table with post_id, wordcount.
I have resource and a new table with resource_id and something.