How to create one-to-many relationship React native Realm SDK

Hi @Mads_Haerup! You may want to consider an inverse relationship in your schemas.

Looks like you’ve got part of it already. TeamSchema has players: Player[], which is correct. However, you need to add a specific field to Player to complete the relationship.

export const PlayerSchema = {
	name: 'Player',
	properties: {
		_id: 'objectId?',
		name: 'string?',
		position: 'string?',
		uri: 'string?',
        // assignee field links the Player back to Team.players.
        assignee: {
          type: 'linkingObjects',
          objectType: 'Team',
          property: 'players'
        }
	},
	primaryKey: '_id',
};

To actually add the player to a team, you need to query for your team. If you’re using the Realm React library, it would look something like this:

const team = useQuery(Team).filtered(`team_name == ${nameOfTeamToFind}`)[0];

After you query for your team, create a new Player object. Then, push the player to Team.players:

team.players.push(newPlayer)

Hopefully, some of this helps!