14.9.1.5 Flexing the Duality of Duality Views

Work with the same data as JSON documents or relational rows, with changes reflected in both.

Duality gives you a JSON-first way to work with your relational data, with both approaches fully functional and always in sync. Tools that prefer JSON use that view, while familiar relational ones keep working as before. For example, suppose you just inserted a new action item – Buy Talulah's Retirement Gift – with two team members as a JSON document into the duality view. As soon as the INSERT transaction commits, the query below immediately returns the team member data for that action item.

select ai.name as action_name, s.name, tm.role
  from action_item_team_members tm
  join action_items ai
    on ai.id = tm.action_id
  join staff s
    on s.id = tm.user_id
 where ai.id = 58
 order by tm.role, s.name
It produces the relational row set result:
ACTION_NAME                    NAME      ROLE
-----------------------------  --------  ------
Buy Talulah's Retirement Gift  Abigail   LEAD
Buy Talulah's Retirement Gift  Chaz      MEMBER

Duality means apps using the relational tables keep working normally. For example, imagine end user Leo uses your existing application page shown below to update the new action item's title from Retirement to Farewell. When he clicks (Apply Changes), the data updates. Any subsequent request of this action item through the duality view instantly reflects the change in the JSON, too.

Figure 14-24 Leo Updates the Title of the New Action Item