RedBeanPHP\Facade::dup PHP Method

dup() public static method

- All beans in own-lists will be duplicated as well - All references to shared beans will be copied but not the shared beans themselves - All references to parent objects (_id fields) will be copied but not the parents themselves In most cases this is the desired scenario for copying beans. This function uses a trail-array to prevent infinite recursion, if a recursive bean is found (i.e. one that already has been processed) the ID of the bean will be returned. This should not happen though. Note: This function does a reflectional database query so it may be slow.
Deprecation: This function is deprecated in favour of R::duplicate(). This function has a confusing method signature, the R::duplicate() function only accepts two arguments: bean and filters.
public static dup ( OODBBean $bean, array $trail = [], boolean $pid = FALSE, $filters = [] ) : array
$bean OODBBean bean to be copied
$trail array for internal usage, pass array()
$pid boolean for internal usage
return array
    public static function dup($bean, $trail = array(), $pid = FALSE, $filters = array())
    {
        self::$duplicationManager->setFilters($filters);
        return self::$duplicationManager->dup($bean, $trail, $pid);
    }

Usage Example

Example #1
0
 /**
  * In the past it was not possible to export beans
  * like 'feed' (Model_Feed).
  *
  * @return void
  */
 public function testExportIssue()
 {
     R::nuke();
     $feed = R::dispense('feed');
     $feed->post = array('first', 'second');
     R::store($feed);
     $rows = R::getAll('SELECT * FROM feed');
     asrt($rows[0]['post'], '["first","second"]');
     $feed = $feed->fresh();
     asrt(is_array($feed->post), TRUE);
     asrt($feed->post[0], 'first');
     asrt($feed->post[1], 'second');
     R::store($feed);
     $rows = R::getAll('SELECT * FROM feed');
     asrt($rows[0]['post'], '["first","second"]');
     $feed = R::load('feed', $feed->id);
     $feed->post[] = 'third';
     R::store($feed);
     $rows = R::getAll('SELECT * FROM feed');
     asrt($rows[0]['post'], '["first","second","third"]');
     $feed = $feed->fresh();
     asrt(is_array($feed->post), TRUE);
     asrt($feed->post[0], 'first');
     asrt($feed->post[1], 'second');
     asrt($feed->post[2], 'third');
     //now the catch: can we use export?
     //PHP Fatal error:  Call to a member function export() on a non-object
     $feeds = R::exportAll(R::find('feed'));
     asrt(is_array($feeds), TRUE);
     $feed = reset($feeds);
     asrt($feed['post'][0], 'first');
     asrt($feed['post'][1], 'second');
     asrt($feed['post'][2], 'third');
     //can we also dup()?
     $feedOne = R::findOne('feed');
     R::store(R::dup($feedOne));
     asrt(R::count('feed'), 2);
     //can we delete?
     R::trash($feedOne);
     asrt(R::count('feed'), 1);
     $feedTwo = R::findOne('feed');
     $feed = $feedTwo->export();
     asrt($feed['post'][0], 'first');
     asrt($feed['post'][1], 'second');
     asrt($feed['post'][2], 'third');
 }
All Usage Examples Of RedBeanPHP\Facade::dup