hyva-themes / magento2-hyva-admin

This module aims to make creating grids and forms in the Magento 2 adminhtml area joyful and fast.
https://hyva-themes.github.io/magento2-hyva-admin/
BSD 3-Clause "New" or "Revised" License
168 stars 39 forks source link

Available DB columns are not properly checked in collection provider #43

Closed jvaughan closed 3 years ago

jvaughan commented 3 years ago

I have a grid configured as

<source>
        <collection>\Magento\Sales\Model\ResourceModel\Order\Collection</collection>
</source>

I have added some columns to the sales_order table and they are correctly populating and accessible with \Magento\Sales\Model\Order::getData().

However if I add them to <columns><include></include></columns> I get the error

1 exception(s):
Exception #0 (OutOfBoundsException): Column(s) not found on source: my_column_name

What I think is happening:

I can see that the module tries to find all column names in the db in addition to finding the getter methods through reflection.

However, \Hyva\Admin\Model\GridTypeReflection::getDbTableColumnKeys calls \Hyva\Admin\Model\TypeReflection\TableColumnExtractor::getTableColumns($tableName) with "Magento\Sales\Model\Order" as the parameter value.

The check therefore fails: the value for $tableName that \Hyva\Admin\Model\TypeReflection\TableColumnExtractor::describeTable ends up checking for doesn't work as the value should be sales_order (the actual table name).

Vinai commented 3 years ago

Hi @jvaughan, thanks for your issue report! Currently available columns are found through inspection of the returned model type, rather than the underlying table. However, I see this is a real requirement.

The table column inspection is only used as a fallback when the collection model type is a generic object (only used for backend grid collections).

Vinai commented 3 years ago

My current idea is to inspect the Select instance for for flat-table collections instead of only looking at the main table for generic entity types. This should then cover your case, as well as support joined tables for the generic type collections.

jvaughan commented 3 years ago

Thanks for the response (and great module!)

Would the array source be the way to go to have these fields included for the time being?

Vinai commented 3 years ago

I've just released 1.1.5 - it would be super cool if you could update to that version and try if that works for you with a collection provider! I'll leave the issue open for a while until I hear back from you.

jvaughan commented 3 years ago

Wow, thanks.

Yes the column does now appear.

I am seeing an issue with boolean filtering on the (smallint) column but will raise a separate issue for that.

Vinai commented 3 years ago

Thanks! One issue at a time is a good way forward!