watermarkchurch / wcc-contentful

An alternative to Contentful's contentful.rb ruby client, contentful_model, and contentful_rails gems all in one.
MIT License
2 stars 1 forks source link

Accomodate "sys" in content queries #245

Open rileyjhardy opened 2 years ago

rileyjhardy commented 2 years ago

Currently the gem does not require specifying "sys" within queries such as...

Page.find_by({ meta: { sys: { id: "someid" } } })

However we want to accomodate the case where we do provide "sys" since that is the actual structure of the content type. We don't want the request adding an additional "sys" as in the screenshot below.

wcc-contentful bug

Below is how the Page object structured

{
{
    "metadata": {
        "tags": []
    },
    "sys": {
        "space": {
            "sys": {
                "type": "Link",
                "linkType": "Space",
                "id": "hw5pse7y1ojx"
            }
        },
        "id": "4MLOHjOkA3lBAWz6WPIDQK",
        "type": "Entry",
        "createdAt": "2020-04-29T00:25:26.141Z",
        "updatedAt": "2021-10-14T17:32:19.511Z",
        "environment": {
            "sys": {
                "id": "master",
                "type": "Link",
                "linkType": "Environment"
            }
        },
        "revision": 18,
        "contentType": {
            "sys": {
                "type": "Link",
                "linkType": "ContentType",
                "id": "page"
            }
        },
        "locale": "en-US"
    }...
jpowell commented 2 years ago

Ahhh - we do allow for querying sys, but not after doing a join, i suppose... @gburgett can you confirm?

jpowell commented 2 years ago

Actually, @rileyjhardy, I believe Page.find_by({ meta: { id: "someid" } }) works... no need for sys

gburgett commented 2 years ago

Yep that's the workaround! Still think in an ideal world Riley's query should be handled

jpowell commented 2 years ago

we can agree to disagree :trollface: - i think the ideal is that the id is accessed like any other attribute, obfuscating the nuance introduced by contentful's schema... the intent was that it behaved similar to active record.

But yes - if you choose to query mimicking the underlying structure, it should work 😺