tombenner / wp-mvc

An MVC framework for WordPress
http://wpmvc.org
MIT License
623 stars 172 forks source link

Using has and belongs to many not pulling has many #264

Closed jose-tog closed 10 months ago

jose-tog commented 10 months ago

class Category extends MvcModel { var $table = '{prefix}' . BMSPC_TABLE_PREFIX . 'categories'; var $display_field = 'name'; var $order = 'Category.name ASC'; var $has_many = array('Product');

}

class Product extends MvcModel { var $table = '{prefix}' . BMSPC_TABLE_PREFIX . 'products'; var $includes = array( 'Category' ); var $display_field = 'style_name'; var $order = 'Product.style_name ASC'; var $has_and_belongs_to_many = array( 'Category' => array( 'join_table' => '{prefix}' . BMSPC_TABLE_PREFIX . 'product_categories', 'fields' => array('id', 'name') ) );

public function after_find($object) {

}

}

I have a category, product and product_categories tables. Trying to show count of Products that belong to a Category but array of products is coming empty.