Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs with R::bindFunc() #841

Closed
marios88 opened this issue Oct 15, 2020 · 4 comments
Closed

Bugs with R::bindFunc() #841

marios88 opened this issue Oct 15, 2020 · 4 comments

Comments

@marios88
Copy link
Contributor

marios88 commented Oct 15, 2020

Tested with latest 5.5 & 5.6 with Mysql & Sqlite

  • $bean->fresh does not apply bindFunc()
  • Shared*List cannot remove items

Please see the following code sample with a demonstration

<?php

require 'rb.5.6.php';

\R::setup('sqlite:'.getcwd().'/bindfunc.sqlite');
\R::nuke();

\R::bindFunc( 'read', 'record.point', 'abs' );
\R::bindFunc( 'write', 'record.point', 'abs' );

for($i = 0;$i < 5;$i++){
    $record = \R::dispense('record');
    $record->point = random_int(-100,-1);
    \R::store($record);
    $record->fresh(); // * fresh does not apply bindFunc
    $record_fetch = \R::load('record',($i+1));
    echo 'Fresh ['.$record->point.'] | Load ['.$record_fetch->point.']'.PHP_EOL;
}

for($i = 0;$i < 3;$i++){
    $tag = \R::dispense('tag');
    $tag->name = 'TAG_'.$i;
    \R::store($tag);
}

$record = \R::load('record',1);
$record->sharedTagList[] = \R::load('tag',2);
\R::store($record);
echo 'Shared Tag Records: got ['.(count($record->sharedTagList)).'], expected [1]' .PHP_EOL;

$record = \R::load('record',1);
$record->sharedTagList = [];
\R::store($record);
$record = \R::load('record',1);
echo 'Shared Tag Records: got ['.(count($record->sharedTagList)).'], expected [0]' .PHP_EOL;

\R::bindFunc( 'read', 'record.point', null );
$record = \R::load('record',1);
$record->sharedTagList = [];
\R::store($record);
$record = \R::load('record',1);
echo 'Shared Tag Records: got ['.(count($record->sharedTagList)).'], expected [0]' .PHP_EOL;
@gabordemooij
Copy link
Owner

Thanks for the report, we will investigate this issue asap.

@gabordemooij
Copy link
Owner

Regarding fresh(), it should be used like this:

$bean = $bean->fresh();

See:
https://redbeanphp.com/index.php?p=/crud

@gabordemooij
Copy link
Owner

This bug has been confirmed.

@gabordemooij
Copy link
Owner

This has been fixed in the master branch.
I used your example as a unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants