Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Forms/Models - belongs_to and has_many - how to specify column to be displayed on the list

edited September 2016 in Modules
Hi,

I have two tables: groups and products. In groups model, I have declared this

public $has_many = array('products' => 'products_model');

And in products model, I have declared this

public $belongs_to = array('groups' => 'groups_model');

It seems the list will be automatically populated with items based on the second column of the other table.

e.g. if table products has columns (in exact order)

id, name, description...

and table groups has columns (in exact order)

id, published, name ...

The create group form will display the list of products via name while the create product form will display the list of groups via published.

e.g.

Create Group Form:
Products
- item 1 (name)
- item 2 (name)
- item 3 (name)
...

Create Product Form:
Belongs to Group
- yes (published)
- yes (published)
- no (published)
...


Can I specify the column/values that I want to be displayed on the list via parameter has_many or belongs_to?

Comments

Sign In or Register to comment.