0

I checked the revisions table in the database and their are revision records for the record I'm trying to show the history for.

$record->revisionHistory returns an empty array though.

The same code for other models works fine, it is really strange.

This model code works:

namespace App\Models\Slack;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes as SoftDeletes;

class Channel extends Model
{
    use SoftDeletes;
    use \Venturecraft\Revisionable\RevisionableTrait;

    protected $revisionEnabled = true;
    protected $revisionCleanup = true;
    protected $historyLimit = 10;
    protected $revisionCreationsEnabled = true;

This controller code for the above model works:

$channel = Channel::find($id);
return $channel->revisionHistory;

This model code doesn't work (but there are records in the database):

namespace App\Models\Organization;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes as SoftDeletes;

class Organization extends Model
{
    use SoftDeletes;
    use \Venturecraft\Revisionable\RevisionableTrait;

    protected $revisionEnabled = true;
    protected $revisionCleanup = true;
    protected $historyLimit = 10;
    protected $revisionCreationsEnabled = true;

This controller code for the model above display an empty array ([]):

$organization = Organization::find($id);
return $organization->revisionHistory;
thestepafter
  • 598
  • 1
  • 4
  • 20
  • In your first example, both lines use `$channel`. In your second, the first line uses `$organization` and the second uses `$organization_history`. Try `$organization->revisionHistory`. – ceejayoz Mar 16 '16 at 02:05
  • Thanks for catching that but that is a typo on my end when I was putting this example. It still doesn't work when I make that change. – thestepafter Mar 16 '16 at 02:16
  • Try doing `$organization->revisionHistory()->toSql()` and see what SQL is generated. Then try running the query yourself directly against SQL. – ceejayoz Mar 16 '16 at 13:45
  • @ceejayoz I ran that and it did display some SQL, the SQL was the same for both the working model and the model that isn't working. select * from "revisions" where "revisions"."revisionable_id" = ? and "revisions"."revisionable_id" is not null and "revisions"."revisionable_type" = ? Is there a way to see what parameters are being passed in? I manually put them and it did return a record: select * from "revisions" where "revisions"."revisionable_id" = 1 and "revisions"."revisionable_id" is not null and "revisions"."revisionable_type" = 'App\Models\Organization\Organization'; – thestepafter Mar 16 '16 at 14:28
  • I believe `$organization->revisionHistory()->getBindings()` gives you the values being passed to `?`. – ceejayoz Mar 16 '16 at 15:05
  • @ceejayoz you are correct, thank you very much. It looks like the morphMap that I have setup in my boot method under the AppServiceProvider class is causing just organization to be passed through. Any suggestions on how to make this work with revisionable? – thestepafter Mar 16 '16 at 16:51

1 Answers1

0

I have a morphMap setup in my AppServiceProvider boot method that is firing when revisionable calls for the record so this is why nothing is being returned. I am going to close this and open a new question that is more relevant.

thestepafter
  • 598
  • 1
  • 4
  • 20