CakePHP 3 associations : Multiple data in one table
I have 2 types of category product-category, and blog-category, How can i use one table for those 2 or more categories ?
There are 3 tables categories, products, and blogs, I want to keep both blog-category and product-category into the categories table and I will call it by cakephp 3 associations.
There will be different data into categories with alias [blog, product].
Now will define the relations Like
- Blogs belongsTo BlogCategories
- Products belongsTo ProductCategories
In this relation definitions there are 2 things have to focus className and conditions array
- className indicate which class is used for this relations, in my situation i use Categories table class.
- Conditions accepts as array of property for joining conditions with category class
if you want more check BelongsTo Associations
Now if i query
It will get all the data which have blog alias in categories Table
Same way we can get ProductCategories data also.
We can keep such different types data into one table using CakePHP 3 associations