Thanks, great trick! Em seg, 14 de dez de 2020 14:19, Jeremy Evans <[email protected]> escreveu:
> On Mon, Dec 14, 2020 at 6:34 AM Rodrigo Rosenfeld Rosas < > [email protected]> wrote: > >> Hi, today I've faced something unexpected. >> >> I've changed one library to increment the model's version and in some >> code using the library, I was comparing the version and the expected failed >> wasn't matching. >> >> Then I noticed that when we do: >> >> model.update version: Sequel.lit('version + ') >> >> Then model.version won't reflect the computed version after the update >> statement. >> >> This is unexpected because I'd assume all around that calling >> model.version would always retrieve the actual value of the field. What >> would be the recommended Sequel way to deal with that? Avoid using literal >> when using the update instance method? Are there any refresh-like methods >> that would only refresh a single column (or a set of columns)? >> > > Model instances deal only with values, not with SQL expressions, and a > literal string is an SQL expression. To deal with SQL expressions, you > should to drop down to dataset level, and Model#this returns a dataset for > the specific instance: > > model.this.update version: Sequel.lit('version + 1') > > Currently, Sequel doesn't offer support for refreshing single columns in > model objects. If the database supports UPDATE RETURNING, you could do: > > model.values[:version] = model.this.returning(:version).update(version: > Sequel.lit('version + 1'))[0][:version] > > Thanks, > Jeremy > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sequel-talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sequel-talk/r7xii3zOozc/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sequel-talk/CADGZSScM2aDH3OoP1tkrd%2BSB%2ByzOwg%3DipxDQzZvTGB8XdOCyGA%40mail.gmail.com > <https://groups.google.com/d/msgid/sequel-talk/CADGZSScM2aDH3OoP1tkrd%2BSB%2ByzOwg%3DipxDQzZvTGB8XdOCyGA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CAGmv%2BwJvz%3DpHy_%2BCwD-sLG7UA3QJbt9N%2BKv11vQY-HaiC04cSw%40mail.gmail.com.
