On Jan 4, 3:47 pm, g_f <[email protected]> wrote:
> Ok, say I have Sequel connected to a database, and I've loaded a bunch
> of models related to the tables from a "lib" directory.
>
> Is there a way to ask Sequel which models were loaded? Or, instead, if
> I iterate over the tables, is there a way to ask Sequel which model is
> associated with a particular table?
Before loading the models:
Sequel::Model.plugin :subclasses
After loading the subclasses:
Sequel::Model.descendents.detect{|c| c.table_name == :foo}
> I guess I could open the "lib" directory and iterate over the files
> there, and "require" each one in turn, which would also let me build a
> table => model relationship but that seems so inelegant.
>
> Seems like there'd be a way to do this via reflection or
> introspection, but I haven't found the right chain of methods or
> attributes yet to get to one of those places.
There isn't currently a way to do so, as it's possible to have models
that use datasets not based on tables or based on multiple tables, as
well as multiple models that use the same table. You could always
create a plugin to do so, by having the model register itself in some
shared hash keyed on the table name.
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
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.