⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation with where based on current record



matbeard
  • profile picture
  • Member

Posted 04 April 2012 - 18:09 PM

When using the set_relation function you can set a where clause in the 4th parameter.

Is it possible for this where clause to refer to a field value from the current record?

For example, I have a table of accounts and a table of users. Each user is related to a single account, but each account also has an account owner, which relates to a single user.

The account owner must have an account_id that matches the current account. Otherwise it would be possible to set the account owner to a user that doesn't belong to that account.

Does that make sense? If so, is it possible?

Thanks in advance.

sbosx
  • profile picture
  • Member

Posted 09 April 2012 - 10:19 AM

I think I have the same question.

More specifically, let's say that I have a table users that can be connected 1-n with the accounts. And I want to have another table that holds a payment for something but we have to select the user and an account of that user from which the payment will be done. I want to make something like the following in the add process:



$this->grocery_crud->set_table('payments')
->set_relation('user_id', 'users', '{id}: {name}')
->set_relation('account_id', 'accounts', '{id}: {bank}', array('user_id' => 'payments.user_id'));


Where payments.user_id will be the user that was selected from the above dropdown menu.

Can I make something like that in grocery CRUD?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 April 2012 - 10:25 AM

I think this post will help you a lot: /topic/224-categories-and-depended-subcategories-at-add-and-edit-form/

sbosx
  • profile picture
  • Member

Posted 10 April 2012 - 08:06 AM

Thanks johnny...