On Thursday, December 6, 2012 7:45:15 PM UTC-8, armanx wrote:

> I know this is an old threat, but I found this to be the only relevant 
> conversation regarding this error.
>
> In my case, I'm loading the models (requiring the model class files) in a 
> Sinatra app, at the config.ru bootstrap stage. The actual connection to 
> the database is handled from within the app, which is initialized after 
> rackup runs though the config.ru file. Thus, the models are loaded prior 
> to the db connection.
>
> I came across this when upgrading Sequel from version 3.30.0 to 3.42.0. 
> Previously (at least as of 3.30.0), models did not complain about being 
> loaded prior to database connection, so why the change now? Any way to 
> disable this behavior (other than sticking to older versions of Sequel)?
>

If it worked at all in earlier versions, it was by accident.  You can use 
the anonymous class syntax to be able to create Sequel::Model subclasses 
without a Database, but considering that model classes without datasets 
aren't very useful, you will eventually run into problems.

In general, you should have a separate file for your model initialization 
that is not dependent at all on your web framework, and require that in 
config.ru.  That way, you can easily access your model code without needing 
to load your web code.  I usually have a file called models.rb in my 
Sinatra apps, so I can do "irb -r ./models and get a irb shell with all my 
model code.

On the other hand, if you must connect to the database inside your app, why 
don't you just require your model files inside the app after the database 
is created?

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/lh483KnzG9gJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to