On Sat, Nov 4, 2023 at 12:55 PM Juan Manuel Cuello <juanmacue...@gmail.com> wrote:
> Hi, > > I'm having problems when using the pg_json extension with models that > load the table name using Seguel.delay. > > DB.extension :pg_json > > This works as expected: > > class Foo < Sequel::Model(DB.from(:foo)) > end > > Foo.new(json_column: { a: 1 }).json_column.class > => Sequel::Postgres::JSONBHash > > But this doesn't: > > class Foo < Sequel::Model(DB.from(Sequel.delay{:foo})) > end > If you use Sequel.delay for a model's dataset, then Sequel cannot determine the schema. Database#schema only supports datasets selecting from a symbol, identifier, qualified identifier, or string. It could theoretically support delayed evaluations, but that's a bad idea in the general case, because there is no guarantee that the value at runtime will be the same as the value at call time (after all, the whole point of the delayed evaluation is to allow for runtime changes). You can try this in your application: class Sequel::Model def self.get_db_schema_array(reload) from = dataset.opts[:from][0] if from.is_a?(Sequel::SQL::DelayedEvaluation) dataset = self.dataset.from(from.call(dataset)) end check_non_connection_error(false){db.schema(dataset, :reload=>reload)} end end That should work around your issue. Thanks, Jeremy -- 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 sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSScU__pr-yM%3DD%2BUuH%3DGBp94v8nH8YnVbD-7Yw8G4zaNMQA%40mail.gmail.com.