question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Treating collections as a resource

See original GitHub issue

I’m submitting a

  • bug report.
  • feature request.

Current Behaviour:

I’ve been speculating for some time now that our treatment of collections as a single resource for every class is wrong. Nowhere in the spec is it mentioned that a collection is a set of all objects for a given class. It is mentioned that a collection is “a set of somehow related resources”. This does not imply that a collection would be only limited to class types

Expected Behaviour:

I think the direction we must move in is for users to be able to define collections on their own. Each collection itself would have an @id since it is a subclass of hydra:Resource. We then use the collection endpoint to relate classes/properties.

We use Collections directly instead of having pseudo-Collections defined by parent_id or child_id. The main problem with both the above approaches is as you mentioned, identifying the property which contains the parent/child id. This is because schema.org/identifier or hydra:Link and even https://schema.org/ItemList are general definitions that can be used for any property and need not necessarily be for only parent/child ids. The advantage of using a collection is that we define a CommentCollection object, where we link all Comment objects for a particular issue. We then give that CommentCollection object as the property for the Issue. In terms of defining it in the API documentation, it would be something like:

{
        "@type": "SupportedProperty",
        "property": vocab:CommentCollection,
        "readonly": "false",
        "required": "true",
        "title": "Comments",
        "writeonly": "false"
}

The property would map to an instance of the CommanCollection class. This will be defined in the supportedProperty field for the definition of the Issue class. Like any other object, when we define the Issue object, we will add the appropriate instance of the CommandCollection to the Issue instance. So an object would be something like:

{
        "@type": "Issue",
        "@id": "/api/Issues/27",
        "Issue": "....",
        "Comments": "/api/CommentCollection/32",
        ....
}

And then /api/CommentCollection/32 would have:

{
        "@type": "CommentCollection",
        "@id": "/api/CommentCollection/32",
        "members": [
                {
                        "@id": "/api/Comment/12",
                        "@type": "Comment"
                },
                {
                        "@id": "/api/Comment/18",
                        "@type": "Comment"
                },
                {
                        "@id": "/api/Comment/22",
                        "@type": "Comment"
                }
        ]

}

All this is part of the bigger implementation of treating collections as a resource. We allow hydrus to implement all operations: GET, PUT, POST, DELETE on all resource endpoints as well as on all collection endpoints. We then let users decide how they design their APIs and wether creation of resources happens at the collection endpoint or the resource endpoint is defined in the API Documentation itself. Nested collection would then be added to an object as any other resource.

NOTE: We should also allow the creation of both resources(Comment) as well as collections(CommentCollection) on the collection endpoint. We let the user decide which they want to use based on the API documentation. If the doc contains a supportedOperation to allow creation of resource using the collection endpoint then we create resources using that. Similarly for the case of resources. Hope this is clear.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
vddesai1871commented, Aug 16, 2019

I think the direction we must move in is for users to be able to define collections on their own.

👍

The main problem with both the above approaches is as you mentioned, identifying the property which contains the parent/child id. This is because schema.org/identifier or hydra:Link and even https://schema.org/ItemList are general definitions that can be used for any property and need not necessarily be for only parent/child ids.

I think this problem can be solved by hydra:Link, by having a ‘bidirectional’ link, as Markus has used here http://www.markus-lanthaler.com/hydra/api-demo/vocab. The solution you proposed is somewhat better than such reliance on links to imply relations, but still I think we will need to have that as fallback or alternative. As we are allowing the Api Designer to decide whether he wants to add new resources from the item resource endpoint or collection resource endpoint, if he chooses the collection endpoint then everything will work fine and we would be able to know whether newly added object belongs to some nested collection of other item resource or not( ex. If new comment is added on api/CommentCollection/3 then we know that the issue (or anyother class) which has this collection object(with id 3) is the parent of this new comment(basically this comment belong to that issue)) But if API designer allows addition on the resource endpoint (Comment/id) then how do we find out which issue this comment belongs to? Then only way for him to accomodate such parent child relation would be to have another link from child to the parent object. So the newly added comment will have a link to the parent issue.

0reactions
chrizandrcommented, Sep 12, 2020

Yes, I think we can close this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Session 3: Caring for Collections - Conservation Treatment
The primary goal of conservation treatment for special collections is twofold: to stabilize the item in the collection so that it survives over...
Read more >
Collections Care (Preservation, Library of Congress)
Collections care information for handling, storing, using, and managing books, works on paper, photographs, audio-visual materials, and other types of ...
Read more >
How to Beat AR Resources | SoloSuit Blog
They can help you contact the hospital and physicians you need to pay before the debt goes to collections. Stop calls from AR...
Read more >
Collections Resources On Your Credit Report? - Credit Glory
Collections Resources is a debt collector reporting a collection account on your credit report. In some cases this means they purchased the debt ......
Read more >
Resources | Connecting to Collections Care Online Community
Connecting to Collections Care is continually evaluating resources that will be of use to smaller cultural institutions to help you readily find information ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found