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

Revisionable and Mutators #21

Closed
mmodler opened this issue Aug 7, 2013 · 13 comments
Closed

Revisionable and Mutators #21

mmodler opened this issue Aug 7, 2013 · 13 comments
Assignees
Milestone

Comments

@mmodler
Copy link

mmodler commented Aug 7, 2013

Hi,

one of my revisionable models has some mutators like getPriceAttribute / setPriceAttribute.

Revisionable's oldValue / newValue irgnores my getter and returns the raw price atrribute?

@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

This would be because the raw data is what is stored in the revisions table, hence the data that is output is simply

$revision->old_value

I'll have a look and see if there's a way to make it smarter, and output using the mutator if available

@ghost ghost assigned duellsy Aug 7, 2013
duellsy added a commit that referenced this issue Aug 7, 2013
@duellsy duellsy closed this as completed Aug 7, 2013
@mmodler
Copy link
Author

mmodler commented Aug 7, 2013

According to the eloquent docs Accessors are named like this:

getFieldnameAttribute

You check for method getFieldname atm, so this can't work for me :)

duellsy added a commit that referenced this issue Aug 7, 2013
@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

Oops... sorry. Fixed up, try that.

@mmodler
Copy link
Author

mmodler commented Aug 7, 2013

And now also in line 140 - thats the problem with redundant code, as always ;)

@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

true

@mmodler
Copy link
Author

mmodler commented Aug 7, 2013

Now the accessor is used. Good! But the main model attributes are not there:

 public function getPriceAttribute() {
    return str_replace('.', ',', $this->attributes['price']);
}

Undefined index: price

@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

Where are you calling the set method from?

Sent from iPhone

On Wed, Aug 7, 2013 at 10:36 PM, mmodler notifications@github.com wrote:

Now the accessor is used. Good! But the main model attributes are not there:

public function setPriceAttribute($price) {
    $this->attributes['price'] = str_replace(',', '.', $price);
}```
Undefined index: price
---
Reply to this email directly or view it on GitHub:
https://github.com/VentureCraft/revisionable/issues/21#issuecomment-22247733

@mmodler
Copy link
Author

mmodler commented Aug 7, 2013

It happens in my Revision detail controller with

$revision = Revision::find(Input::get('revision_id', null))

@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

Not sure why that would call the set mutator. Don't suppose you have a full stack trace?

Sent from iPhone

On Wed, Aug 7, 2013 at 10:42 PM, mmodler notifications@github.com wrote:

It happens in my Revision detail controller with

$revision = Revision::find(Input::get('revision_id', null))

Reply to this email directly or view it on GitHub:
#21 (comment)

@mmodler
Copy link
Author

mmodler commented Aug 7, 2013

It really should! If i load a single revision i also want to have nice "mutated" data.

Stack trace:

ErrorException
…/­app/­models/­Seminardate.php34
Illuminate\Exception\Handler handleError
…/­app/­models/­Seminardate.php34
App\Models\Seminardate getPriceAttribute
…/­vendor/­venturecraft/­revisionable/­src/­Venturecraft/­Revisionable/­Revision.php142
Venturecraft\Revisionable\Revision getValue
…/­vendor/­venturecraft/­revisionable/­src/­Venturecraft/­Revisionable/­Revision.php61
Venturecraft\Revisionable\Revision oldValue
…/­app/­controllers/­admin/­RevisionsController.php20
App\Controllers\Admin\RevisionsController getRevisionJson
<#unknown>0
call_user_func_array
…/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Controllers/­Controller.php138
Illuminate\Routing\Controllers\Controller callMethod
…/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Controllers/­Controller.php115
Illuminate\Routing\Controllers\Controller callAction
…/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Router.php985
Illuminate\Routing{closure}
<#unknown>0
call_user_func_array
…/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Route.php80
Illuminate\Routing\Route callCallable
…/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Route.php47
Illuminate\Routing\Route run
…/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Router.php1016
Illuminate\Routing\Router dispatch
…/­vendor/­laravel/­framework/­src/­Illuminate/­Foundation/­Application.php522
Illuminate\Foundation\Application dispatch
…/­vendor/­laravel/­framework/­src/­Illuminate/­Foundation/­Application.php497
Illuminate\Foundation\Application run
…/­public/­index.php49

@mmodler
Copy link
Author

mmodler commented Aug 7, 2013

Stop thinking! ;) It was my fault. With accessors i should use getFieldnameAttribute($value) and work with $value, not with $this...

@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

What is the line of code that is causing the problem?

Revisionable doesn't call any setSomeAttribute() mutators, it only calls the getSomeAttribute() accessor

Your stack trace looks like it's calling the getPriceAttribute accessor, but there's no reference to the setPriceAttribute being called... or am I missing something?

@duellsy duellsy reopened this Aug 7, 2013
@duellsy
Copy link
Member

duellsy commented Aug 7, 2013

Ahhh, awesome. All sorted then.

@duellsy duellsy closed this as completed Aug 7, 2013
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