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.

Relationships normalization

See original GitHub issue

Hi Yury,

I’m facing new problems with the relationships normalization:

Data representation feature

With The data repesentation feature of one-to-many relationship, we lost the type “collection” if the collection contains only one element. I have some issues here with the redux-object build function. The single element collection builded is an object instead of an array containing one object.

I agree the fact data representation as a string is useful in a redux context. A naive approach can be adding a new special key to the metas to know the type of the relation (object or collection).

I’m not confident to add a special key to store it… but there is some examples to show how it can be represented:

  1. Collection with a single object
relationships: {
    comments: {
        __relation_type: 'collection',
        id: '295',
        type: 'question'
    }
}
  1. Collection with multiple objects
relationships: {
    comments: {
        __relation_type: 'collection',
        id: '295,678',
        type: 'question'
    }
}
  1. Object relationship
relationships: {
    author: {
        __relation_type: 'object',
        id: '23',
        type: 'author'
    }
}

The redux-object has also to be updated to understand these new properties.

Empty relationships

If a relationship has no data (null) or an empty collection ([]) and links, only the links will be normalized. We lost here the fact that the relation points to an empty data or collection. The redux-objectbuild will raise a lazy loading error when we want to access the relationship. Even if we know there is no data to return.

Following the precedent naive approach, i suggest to store only the collection type:

relationships: {
    author: {
        __relation_type: 'object',
    }
}

The redux-object has also to be updated to understand that the data is already loaded and not try to lazy load something.

I’m currently working on a prototype with this approach, but if you had any suggestions or direction, I’ll follow it and submit a PR for the community.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-dymovcommented, Mar 14, 2017

Ok, I see. Will deliver update by the end of the week for both redux-object and json-api-normalizer.

PRs are also welcome 😃

0reactions
yury-dymovcommented, Mar 15, 2017

closed via PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Things To Start Normalizing In Relationships | by Kirstie Taylor
It's time to start normalizing certain things in relationships, starting with these: Regularly checking in with each other. One of my most viral ......
Read more >
Relationships and Data Normalization - DATAVERSITY
Data normalization is the process of identifying relationships in the data and adjusting the data structure according to those relationships to ...
Read more >
Chapter 12 Normalization – Database Design – 2nd Edition
Normalization is the branch of relational theory that provides design insights. It is the process of determining how much redundancy exists in a...
Read more >
5 Things That Are Okay To Normalize In Relationships
1.Prioritizing Partnership Over Marriage · 2.Keeping Friends on a Need to Know Basis · 3.Being Together While Living Separately · 4.Loving From an ......
Read more >
Relational Database Normalization Process
This process of specifying and defining tables, keys, columns, and relationships in order to create an efficient database is called normalization.
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