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

Exporting a bean that is stored has different results than one that is not stored #947

Open
krisives opened this issue Sep 18, 2024 · 1 comment

Comments

@krisives
Copy link
Contributor

When exporting a bean currently it will export different information based on if the bean has been stored or not.

Firstly, it's understood that the id column of a bean that has not yet been stored will be zero. This issue is not about that.

R::setup("sqlite:./test.db");

$author = R::dispense('author');
$author->name = 'Some Guy';

$book = R::dispense('book');
$book->title = 'Every Book Makes Someone Mad';
$book->author = $author;

// R::store($book);

var_dump($book->export());

The above code (without storing the bean) will output:

array(3) {
  ["id"]=>
  int(0)
  ["title"]=>
  string(28) "Every Book Makes Someone Mad"
  ["author"]=>
  array(2) {
    ["id"]=>
    int(0)
    ["name"]=>
    string(8) "Some Guy"
  }
}

However, if you uncomment that line and actually store the bean, you will get a different output:

array(3) {
  ["id"]=>
  string(1) "1"
  ["title"]=>
  string(28) "Every Book Makes Someone Mad"
  ["author_id"]=>
  string(1) "1"
}

Lastly, if we change the export() invocation to set $onlyMe = true and still export an unstored bean, like this:

R::setup("sqlite:./test.db");

$author = R::dispense('author');
$author->name = 'Some Guy';

$book = R::dispense('book');
$book->title = 'Every Book Makes Someone Mad';
$book->author = $author;

// R::store($book);

var_dump($book->export(false, false, true));

We still get an export that contains the author bean, despite the $onlyMe argument somewhat indicating this is not expected behavior.

Let me know if I can be of any help!

@Lynesth
Copy link
Collaborator

Lynesth commented Sep 19, 2024

#739 (comment)

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

No branches or pull requests

2 participants