atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

Add `first()` function for backref arrays with intermediate table #665

Open sirex opened 4 days ago

sirex commented 4 days ago

If we have following manifest table:

d | r | b | m | property    | type    | ref              | prepare
example                     |         |                  |
                            |         |                  |
  |   |   | Language        |         |                  |
  |   |   |   | name@en     | text    |                  |
  |   |   |   | countries[] | backref | Country          |
                            |         |                  |
  |   |   | Country         |         |                  |
  |   |   |   | name@en     | text    |                  |
  |   |   |   | languages   | array   | CountryLanguage  |
  |   |   |   | languages[] | ref     | Language         |
  |   |   |   | language    | ref     | Language         | languages.first(null)
                            |         |                  |
  |   |   | CountryLanguage |         |                  |
  |   |   |   | country     | ref     | Country          |
  |   |   |   | language    | ref     | Language         |

We have

language ref Language prepare: languages.first(null)

Which takes first value from languages and uses it as direct many-to-one relation with Language.

If Country does not have any assigned languages, then null value should be returned as specified in the first arguments.

Resources

Related