Merge pull request #86 from axellebot/patch-1

[FIX] Fixed wrong relationship example
This commit is contained in:
Tobe Osakwe 2019-07-17 18:41:54 -04:00 committed by GitHub
commit 6bad589fde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,16 +110,18 @@ class CarController extends Controller {
@Expose('/recalled_since_2008') @Expose('/recalled_since_2008')
carsRecalledSince2008(QueryExecutor executor) { carsRecalledSince2008(QueryExecutor executor) {
// Instantiate a Car query, which is auto-generated. This class helps us build fluent queries easily. // Instantiate a Car query, which is auto-generated. This class helps us build fluent queries easily.
var cars = new CarQuery(); var query = new CarQuery();
cars.where query.where
..familyFriendly.equals(false) ..familyFriendly.equals(false)
..recalledAt.year.greaterThanOrEqualTo(2008); ..recalledAt.year.greaterThanOrEqualTo(2008);
// Shorter syntax we could use instead... // Shorter syntax we could use instead...
cars.where.recalledAt.year <= 2008; query.where.recalledAt.year <= 2008;
// `get()` returns a Future<List<Car>>. // `get()` returns a Future<List<Car>>.
return await cars.get(executor); var cars = await query.get(executor);
return cars;
} }
@Expose('/create', method: 'POST') @Expose('/create', method: 'POST')
@ -154,15 +156,15 @@ with custom parameters (ex. `@HasOne(foreignKey: 'foreign_id')`).
@orm @orm
abstract class _Author extends Model { abstract class _Author extends Model {
@hasMany // Use the defaults, and auto-compute `foreignKey` @hasMany // Use the defaults, and auto-compute `foreignKey`
List<Book> books; List<_Book> books;
// Also supports parameters... // Also supports parameters...
@HasMany(localKey: 'id', foreignKey: 'author_id', cascadeOnDelete: true) @HasMany(localKey: 'id', foreignKey: 'author_id', cascadeOnDelete: true)
List<Book> books; List<_Book> books;
@SerializableField(alias: 'writing_utensil') @SerializableField(alias: 'writing_utensil')
@hasOne @hasOne
Pen pen; _Pen pen;
} }
``` ```