Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

inflection ignored in lookup by RelationshipView #790

Closed
@sdhawley

Description

I did a quick search and didn't find a similar issue, but I apologize if I missed one on this topic. And, maybe this is an enhancement request rather than a bug report. It is an inconsistency in type names between the url and rendered document.

For an api view of a model I have eg http://localhost/api/customer-accounts/ where the relationship type (lets just call it relationship-name) is inflected correctly according to the setting JSON_API_FORMAT_TYPES (dasherized, in this case)

{
 "links": {
 "first": "http://localhost/api/customer-accounts/?page%5Bnumber%5D=1",
 "last": "http://localhost/api/customer-accounts/?page%5Bnumber%5D=1",
 "next": null,
 "prev": null
 },
 "data": [
 {
 "type": "customer-accounts",
 "id": "1",
 "attributes": {
 "account-id": 1,
 "account": "1234",
 "insert-ts": "2020年05月20日T20:42:52.895506Z",
 "update-ts": "2020年05月20日T20:42:52.895643Z"
 },
 "relationships": {
 "relationship-name": {
 "data": {
 "type": "relationship-name",
 "id": "1"
 }
 }
 }
 }
 ],
 "meta": {
 "pagination": {
 "page": 1,
 "pages": 1,
 "count": 1
 }
 }
}

Then I go to eg http://localhost/api/customer-accounts/1/relationships/relationship-name/ and get a 404. Instead, I find the relationship at http://localhost/api/customer-accounts/1/relationships/relationship_name/ which looks like:

{
 "data": {
 "type": "relationship-name",
 "id": "1"
 }
}

The rendered document has the correctly inflected type, which doesn't match the url.

I am working around this for now using field name mapping in RelationshipView

field_name_mapping = {
 'relationship-name': 'relationship_name'
 }

Could RelationshipView pass relationship-name through the inflector first to get it back to the internal python (underscore) convention?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /