Skip to content

[Feature Request] Abstract Relation logic to Core to enable better support of Non-eloquent relations #33

Open
@DellanX

Description

@DellanX

Use Case

I have a model, Calendar, which has events from the database (An Eloquent model occasion)
But now, I am adding support for external events, such as an ICalendar Feed (a URL for .ics files)

I can get the data into Laravel pretty easy, and I have a relationship on calendar called occurrences which combines occasions and all external events into a collection. Data has attributes to distinguish the source and ids, so my custom repository can handle CRUD operations.

I need to be able to interact with this via JSON API at the route /calendars/{calendar}/occurrences

Code changes

The issue, is that that the following code checks specifically if the Schema is an Eloquent Schema.

if ($schema instanceof Schema) {

I could resolve this, by making the typecheck compare against LaravelJsonApi\Core\Schema\Schema instead of LaravelJsonApi\Eloquent\Schema

But this opens a whole new can of worms. Thinks like Paginator, and another type check at:

assert($relation instanceof EloquentRelation, sprintf(

Conclusion

I am very much willing to assist in any code development needed here, but it seems to me like a lot of code is going to need to be touched to trick this library to be able to support non-eloquent relations.

I figure, the best bet, is to try and move some of this logic up to the Core Level, so that any LaravelJsonAPI schema.
And my current efforts are to reduce the scope of the Type Checks to the Core Level. That being said, I'll also need to move some of the logic from the eloquent library to the core library, to fix some of these type checks.

Let me know if y'all have any concerns, or if there are any ongoing efforts that I can assist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions