JSON API in aqueduct doubt

Asked

Viewed 35 times

1

I created an API in aqueduct initially. In it I created a serial model class and inside it I have information about autor, ano, idserie , blz there wanted to create a class model episodes she would have the idepsodio ,episodios, idserie(here and Foreign key of the series table).

How can I relate the episodes to the series? This is the first time I’ve done API.

Follow down what I’ve done so far:

class Serie extends ManagedObject<_Serie> implements _Serie{
 String get detail=>'$idserie by $autor';
}

class _Serie{
@primarykey
Int Idserie;

@Culumn()
String autor;

@Column()
Int ano;}

1 answer

1


Relating is very simple, it’s a 1-to-n relation, in Serie you have to put an object ManagedSet where then you can use it to fetch the spikes and the object Episodio places the normal Serie class with an Annotations Related pointing to the Managedset of the Serie.

This is how the Series class looks:

class Serie extends ManagedObject<_Serie> implements _Serie{
}

class _Serie{
@primarykey
 int Idserie;
 ...
 ManagedSet<Episodio> episodiosDaSerie;
}

And the class Episodio:

class Episodio extends ManagedObject<_Episodio> implements _Episodio{
}

class _Episodio{
@primarykey
 int IdEpisodio;
 ...
 @Related(#episodiosDaSerie)
 Serie serie;    

}
  • Right and how would I get her ? From the id 1 series with her episodes can give an example?

  • You can see better here https://aqueduct.io/docs/tut/executing-queries/#executing-queries

  • final query = Query<Episode>(context).. Where((e) => e.serie.idSerie ).equalTo( 1 )

  • Got it in the others I call series instead of episode in query?

  • I don’t understand what you mean.

  • No Query<episode> instead of query<Serie> would be same episode

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.