Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Update table_through with foreach (user_id field)
  • other question related

    what is the best way to update the table_through in my controller doing a foreach() ?

    protected static $_many_many = array(
        'mailbox' => array(
            'key_from' => 'id',
            'key_through_from' => 'mailbox_id', 
            'table_through' => 'mailboxes_users',
            'key_through_to' => 'user_id', 
            'model_to' => 'Model_Users',
            'key_to' => 'id',
            'cascade_save' => true,
            'cascade_delete' => false,
  • HarroHarro
    Accepted Answer
    Normally you wouldn't need to update the through table, that happens automatically when you update the relations in the many-many.

    If you have data in your through table, you shouldn't access it through the many-many (you can't), you need to define a second has-many relation and a model for the though table. And use the model to update the table.
  • Ohh thaks now works :-)
  • Something are wrong 

    i have this:

    $mailbox = Model_Mailbox::forge(array(
    'user_id' => $userid,
    'subject' => Input::post('subject'),
    'type' => Input::post('type'),
    'featured' => Input::post('featured'),
    'message' => Input::post('message'),
    'status' => 1,
    $mailbox->mailboxes_users[] = Model_Mailboxes_Users::forge(array('user_id' => Input::post('users')));

    the Input::post('users') is multi select but only inser one record in the related table, what is wrong?
  • My model #1

    protected static $_has_many = array(
       'mailboxes_users' => array(
           'key_from' => 'id',
           'model_to' => 'Model_Mailboxes_Users',
           'key_to' => 'mailbox_id',
           'cascade_save' => true,
           'cascade_delete' => true,

    My Model #2

    protected static $_belongs_to = array(
       'mailbox' => array(
           'key_from' => 'id',
           'model_to' => 'Model_Mailbox',
           'key_to' => 'mailbox_id',
           'cascade_save' => true,
           'cascade_delete' => true,

  • I think the problem is the way the multiselect tos post the data ..

    i try with

      foreach (Input::post('users') as $user) {
    echo $user;

    and don't work
  • finnally i solved it 

    select name="users[]"

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion