This commit fixes handling of branches when using both V3 and V2. The
changes include:
* proper definition of relationships that reflect V3 structure, so for
example build belongs to a branch
* setting up inverse records for some of the relationships. without
doing that Ember Data can handle relationships in a surprising way,
for example if the same record is referenced in 2 places in a
belongsTo relationship, Ember Data will remove one of the references
without proper inverse definitions
* we need to add id when extracting branch as a relationship. Ember
Data expects all of the relationships to have an id
* lastly, we need to mimic the structure of the V3 API in V2 payloads,
so for a build payload I'm now creating a branch record
V3 API doesn't return any of the records more than 2 times. If a record
is already included in the response any other occurences will be
represented as a reference, ie. a hash with just an @href. Ember Data
doesn't play nice with such references as it needs an id to identify a
record.
The code in this commit traverses payloads from V3 API and adds an id to
each of the references that are present.
For example a following payload:
{
"@href": "/build/1",
"@type": "build"
"id": 1,
"state": "passed",
"branch": {
"@href": "/repo/1/branch/master",
"name": "master",
"lastBuild": {
"@href": "/build/1"
}
}
}
Will be changed to:
{
"@href": "/build/1",
"@type": "build"
"id": 1,
"state": "passed",
"branch": {
"@href": "/repo/1/branch/master",
"name": "master",
"lastBuild": {
"@href": "/build/1",
"id": 1
}
}
}
In this case an "id" field was added to "branch.lastBuild" field.
One thing that is not standard here is a serializer for branch, which
uses @href as id. At this point branches don't have ids and ember-data
needs one, so using @href is the easiest way.
This commit adds adapters and serializers for v3, but also a fallback
serializer for v2, which allows to handle v2 and v3 payloads at the same
time. This is needed, because when we use v3 endpoint for one of the
models (in this case repo), we can also get embedded records of other
types (like branch or build).