Closed jpowell closed 6 years ago
@gburgett still a WIP. Some things need to move around and be cleaned up / consolidated, but have the basis for moving forward.
Question on dev interface. We could go a couple different routes here. Both have their benefits.
# Option A (in this PR)
# Pro: treats all fields the same in interface, hides contentful semantics
# Con: makes assumptions about data structure and prevents using fields that may collide with "reserved" keywords in sys (id, space, contentType, etc)
Page.find_by(subpages: { id: '1324asdfadsf' })
# Option B
# Pro:
# - simplifies implementation and assumptions to make on query arguments
# - explicit reflection of contentful's underlying semantics
# Con: must pass full representation for queries
Page.find_by('fields.subpages' => { 'sys.id' => '1234adfasdf' })
# Option C
# Pro:
# - combine the above, allows for simplified querying and allows for using sys fields in your model
# - simplifies implementation and assumptions to make on query arguments
# Con: must prefix reserved keywords (sys) with `_` and know which fields to do so with
Page.find_by(subpages: { _id: '1234asdffsdf' })
I definitely think the most common case needs to be most convenient, i.e.:
Page.find_by(slug: 'asdf')
I can get behind supporting option A, if we did it this way on conflicts:
# {
# "sys": { "space": { "sys": { "id": "1xab" } } },
# "fields": [
# "space": { "en-US": "foo" }
# ]
# }
# Finds by the field named "space":
Page.find_by(space: "foo")
# Finds by the space with ID "1xab"
Page.find_by('sys.space.sys.id' => '1xab')
i.e. if the content type has a field named "space" that takes precedence. Of course that would require the query builder to know the content type which may make this undesirable.
My favorite is option C so far
closes #30