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

String instead of Attribute passed down in AttributeBag #32

Closed
ghost opened this issue Oct 22, 2015 · 4 comments
Closed

String instead of Attribute passed down in AttributeBag #32

ghost opened this issue Oct 22, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 22, 2015

I am trying to store an array of data as a meta attribute. This attribute gets stored as JSON with a meta_type of StdClass.

Now when I retrieve a model directly and retrieve the meta attribute like this Post::first()->options everything is working fine. Now comes the weird issue.

When I want to retrieve the model through a relationship and try to access the meta attribute like this Category::first()->posts()->first()->options I get the following exception.

Argument 1 passed to Sofa\Eloquence\Metable\AttributeBag::addInstance() must be an instance of Sofa\Eloquence\Metable\Attribute, string given, called in /home/vagrant/Code/homestead/vendor/sofa/eloquence/src/Metable/AttributeBag.php on line 66 and defined

When I dump the value that is passed down in Line 66 it is the value of the meta_value column instead of an Attribute instance.

What could cause this issue? I am trying to figure it out but can't really find anything.

@jarektkaczyk
Copy link
Owner

I will take a look at this.

@jarektkaczyk
Copy link
Owner

@DraperStudio please paste the data and your code. It seems odd that you get different results in this case.

The best would be calls from tinker, where you store the value, then get it with error.

@ghost
Copy link
Author

ghost commented Oct 23, 2015

Psy Shell v0.5.2 (PHP 5.6.14-1+deb.sury.org~trusty+1 — cli) by Justin Hileman
>>> namespace App;
=> null
>>> Post::first()->options
=> [
     "some_option" => false,
     "another_option" => false,
   ]
>>> Category::first()->posts()->first()->options
=> Argument 1 passed to Sofa\Eloquence\Metable\AttributeBag::addInstance() must be an instance of Sofa\Eloquence\Metable\Attribute, string given, called in /home/vagrant/Code/homestead/vendor/sofa/eloquence/src/Metable/AttributeBag.php on line 66 and defined
>>>

@jarektkaczyk
Copy link
Owner

fixed in 5.1.5

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

1 participant