Jaguar-dart / jaguar_orm

Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
https://jaguar-dart.github.io
BSD 3-Clause "New" or "Revised" License
217 stars 52 forks source link

Improve code generator for update function. #71

Closed ethimjos-velo closed 6 years ago

ethimjos-velo commented 6 years ago

Problem: The generator adds an additional await keyword when generating the code for the update function.

Future<int> update(Book model,  {bool cascade: false, bool associate: false, Set<String> only}) async {                
        final Update update = updater.where(this.id.eq(model.id)).setMany(toSetColumns(model, only: only));
    final ret = adapter.update(update);
    if (cascade) {
        Book newModel;
        if (model.users != null) {
            for (final child in model.users) {
                await await userBean.update(child);
            }
        }
    }
    return ret;
}

Cause: Taking a look at the generator's writer class, line 473, I saw that there is an additional call to the _writeln() function which prints the await keyword.

if (!p.hasMany) {
    _write('await ' + _uncap(p.beanInstanceName) + '.update(model.' + p.property + ');');
} else {
    _writeln('for(final child in model.${p.property}) {');
    if (p is PreloadOneToX) {
        _writeln('await ' + _uncap(p.beanInstanceName) + '.update(child);');
    } else if (p is PreloadManyToMany) {
        _writeln('await ');
        _writeln('await ${p.targetBeanInstanceName}.update(child);');
    }
    _writeln('}');
}

Suggested Fix : Remove the redundant function call _writeln('await ') at line 473;

tejainece commented 6 years ago

Good observations. Thanks for the report. I will fix this.

tejainece commented 6 years ago

Should be fixed by https://github.com/Jaguar-dart/jaguar_orm/commit/679f53b681fdd5f1e99ca359c595ab264ae1e8b8.

Please reopen the issue if this does not fix it.

Thanks!