__sql__ Delegate Method[Permalink]return to Delegate class methods SynopsisThe __sql__ delegate class method can be defined in any delegate class to specify the SQL query that should be used to fetch records for a given table. This method overrides the __sql__? directive of the fields.ini file. This strategy is primarily used to graft columns from another table onto the base table. Use CautionThis is an advanced feature and, if used incorrectly, can muck up your application. Make sure that your SQL query includes a superset of the columns in the base table, and is a row-for-row match for the rows in the base table. I.e. you should never use an internal join. Always use a left join so that all of the rows of the base table are returned even if the join table doesn't have a corresponding row. If you want to simply filter a table's records, and don't need to graft any additional columns onto the table, you should use the setSecurityFilters method. ExampleGiven the table foo, its delegate class:
This effectively grafts a column "category_name" onto the foo table based on a join with the categories table. blog comments powered by Disqus |