Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1433

Joomla! 4.x Coding • Re: Can an instance of Table() class refer to a join of two tables from a database?

$
0
0
After some trials I found a solution. In my "customers" table I have a column "product_id" that refers to a (single) product that a customer purchased. Adding the following field to the form creates a list with titles of all of the possible products and preselects the one based on "product_id" value in the original "customer" table. The name of the field and attribute in "customers" table must match for this to work.

I wonder whether this is documented somewhere. I found it by trial and error.

Code:

<field  name="product_id"  type="sql"  label="COM_EXAMPLE_PRODUCT"  query="SELECT id, title FROM #__products"  key_field="id"  value_field="title"header="COM_EXAMPLE_PRODUCT_SELECT"/>
My original assumption that I need to join the "customers" and "products" table so that I can get full product name in a form was therefore wrong. I can operate over a single table ("customers") using the Table() class and get e.g. full titles of possible products that sit in another table using the above approach.

Statistics: Posted by JanoD — Sat Aug 10, 2024 9:47 am



Viewing all articles
Browse latest Browse all 1433

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>