New foreign key problem (all code included)

55 views
Skip to first unread message

bill

unread,
Apr 15, 2013, 1:53:00 PM4/15/13
to redbe...@googlegroups.com
Hi everyone ,

I am having problems with setting an ownlist. I have 2 bean types/tables  template, and workers. In my controller I run:

 $this->template_model->setItUp();
 $this->worker_model->setItUp();

I have the following functions:

public function setItUp() {

             R::exec('DROP TABLE IF EXISTS `template`');
            
            
          $template=  R::dispense('template');
          $template->phrase = "text1 --1";
          $id=R::store($template);
          unset($template);
          
          $template=  R::dispense('template');
          $template->phrase = "text 2 ";
          $id=R::store($template);
                    unset($template);

          
          $template=  R::dispense('template');
          $template->phrase = "text 3";
          $id=R::store($template);
                    unset($template);
     } 


public function setItUp() {

            R::exec('DROP TABLE IF EXISTS `workers`');
            
            $templateBeans=R::findAll('template');
            $templateBean=$templateBeans[1];
            
          $worker=  R::dispense('workers');
          $worker->name = 'jim';
          $worker->ownTemplate = array($templateBean);
          $id=R::store($worker);
          
          $worker=  R::dispense('workers');
          $worker->name = 'dave';
          $worker->ownTemplate = array($templateBean);    
          $id=R::store($worker);

     } 

the worker table looks like:

idphraseworkers_id
1 text1[->]
2text2NULL
3text 3NULL
4text 4NULL

Any ideas what I'm doing wrong?

Thanks,

Bill



gabor

unread,
Apr 15, 2013, 3:27:03 PM4/15/13
to redbe...@googlegroups.com


You can't assign a templateBean to multiple workers using an ownList.

See:
http://www.redbeanphp.com/adding_lists

"Adding the same building to another village causes the other village to steal the building!"

Also you say the worker table looks like that, but over here this is how the template table looks like.
Aren't you confusing both ends of the own-relationship?

Does 1 worker need multiple templates? $worker->ownTemplate or $template->worker = $worker //see, can only be one
Does 1 template need multiple workers? $template->ownWorker or $worker->template = $template //see, can only be one

Otherwise use a shared list:

$worker->sharedTemplate = array( $template );

Now you can share this template among many workers and the other way around.

Hope this helps...

Cheers,
Gabor

k c

unread,
Apr 16, 2013, 8:28:54 AM4/16/13
to redbe...@googlegroups.com
Gabor,

Your explanation makes more sense than the way I was thinking of it. I have made the changes to a shared list and so far things seem to be working correctly.

Thank you,

Bill


--
You received this message because you are subscribed to the Google Groups "redbeanphp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbeanorm+...@googlegroups.com.
To post to this group, send email to redbe...@googlegroups.com.
Visit this group at http://groups.google.com/group/redbeanorm?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Аби Раджабова

unread,
Apr 28, 2017, 4:13:41 AM4/28/17
to redbeanphp
Hello. How can I print text instead of a foreign key?

понедельник, 15 апреля 2013 г., 20:53:00 UTC+3 пользователь bill написал:
Reply all
Reply to author
Forward
0 new messages