laravel-streams / streams-core

Streams is an open-source web application engine for Laravel.
https://streams.dev
Other
169 stars 99 forks source link

Table Builder / Stream Model #115

Closed websemantics closed 9 years ago

websemantics commented 9 years ago

I'm getting an unexpected behaviour from the TableBuilder/TableColumn etc and Stream Model, ..

After fresh install, this is what I get from a TableBuilder, for a custom Module,

screencapture-localhost-pyro-public-admin-storage-1434827619928

This happens - I figured - because the StreamModel will only return 1 assignment, hence, 'Name' is the only one recognized,

If I change line 310 in the https://github.com/anomalylabs/streams-platform/blob/1.0/develop/src/Stream/StreamModel.php#L310 to

public function getAssignments() { return $this->assignments()->get(); }

That would get it to work,

screencapture-localhost-pyro-public-admin-storage-1434827676642

Any thought of why this is?!

Many thanks

RyanThompson commented 9 years ago

Assignments is a relationship. The difference between what I'm doing and what you're doing it you are forcing it to fetch results. Sounds like the model hydration isn't working properly in this case.

If you look in your compiled model for that stream do you see the assignments that are not working properly?

Try running php artisan streams:recompile

I think that's the right command. See if that fixes it.

RyanThompson commented 9 years ago

When the model loads its compiled data to actual model relations it's not getting picked up.

StreamModel->make() is the function in which that happens.

websemantics commented 9 years ago

Excellent diagnosis Ryan, ..

I did,

artisan streams:compile artisan cache:clear

That fixed the problem,

It's probably my fault regarding the model hydration not working properly, (I've overridden the entire process with custom classes) .. I'll look into the code and see why it fails to re-compile after adding the first assignment,

Many thanks for that,

RyanThompson commented 9 years ago

Lol care to share your additions? You're binding extending classes or replacing all together? Might make sense to merge in some of your changes ^_^

websemantics commented 9 years ago

I'm binding classes,

    protected $bindings = [
        /* Override PyroCMS Classes */
        'Anomaly\Streams\Platform\Stream\Contract\StreamInterface'           => 'Websemantics\StreamsPlatformExtension\Stream\StreamModel',
        'Anomaly\Streams\Platform\Stream\StreamModel'                        => 'Websemantics\StreamsPlatformExtension\Stream\StreamModel',
        'Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface' => 'Websemantics\StreamsPlatformExtension\Stream\StreamRepository',
        'Anomaly\Streams\Platform\Stream\StreamRepository'                   => 'Websemantics\StreamsPlatformExtension\Stream\StreamRepository',
        'Anomaly\Streams\Platform\Entry\EntryModel'                          => 'Websemantics\StreamsPlatformExtension\Entry\EntryModel',
        'Anomaly\Streams\Platform\Assignment\AssignmentModel'                => 'Websemantics\StreamsPlatformExtension\Assignment\AssignmentModel'
    ];

I've created an extension for this called, StreamsPlatformExtension

This extension is useful for someone who wants to gain full control over core streams/fields/assignments functionality including the creation of models / translation etc, .. I can share if that sounds useful to anybody :)

RyanThompson commented 9 years ago

Cool! I think it might be something to put up on the market or something ya. If anything to learn from.

websemantics commented 9 years ago

Just uploaded the code, .. check it here, https://github.com/websemantics/streams_platform-extension