Currently there's only basic reflection available- you can do DB.tables and DB[:table].columns
Aman Gupta On Jan 14, 12:31 pm, dan yoder <[EMAIL PROTECTED]> wrote: > After a little more research, I am pretty sure there is no support for > schema reflection as yet. > > Getting more detailed column_info is easy enough in principal. For > MySQL: > > Application.database['show columns from entries'].map do |column| > { :type => column[:Type].match(/^\w+/)[0].intern, > :name => column[:Field].intern } > end > > # => [{:type=>:int, :name=>:id}, > # {:type=>:text, :name=>:name}, > # {:type=>:text, :name=>:title}, > # {:type=>:text, :name=>:summary}, > # {:type=>:timestamp, :name=>:created_on}, > # {:type=>:timestamp, :name=>:updated_on}, > # {:type=>:text, :name=>:author}, > # {:type=>:text, :name=>:content}] > > This is probably non-standard SQL and would have to be incorporated > into each driver. The types returned would also have to be normalized, > of course (i.e., :int to :integer). > > No reflection data is presently kept in the model for associations. To > really produce a complete :record_info (or whatever it would be > called), we need to add in the association data. This could be > captured easily just by modifying the one_to_one, one_to_many, etc., > methods and keeping the metadata around in a class instance variable. > At least, I don't see any complication from doing that. > > I will work on this but would like to make sure no one else is already > doing so, so we don't duplicate efforts. Any thought / suggestions? > > Regards, > Dan > > On Jan 10, 4:07 pm, dan yoder <[EMAIL PROTECTED]> wrote: > > > Kudos the folks working on this project. It is fantastic work. > > > It appears that you can get access to the columnar meta-data for a > > model via the schema attribute of a database, but how can you reflect > > on the associations of a model? Is there any plan (or interest) in > > having this metadata be reflected directly from the model. I > > implemented this once for ActiveRecord, but never released it because > > I stopped working with AR. :) > > > You would use it like this: > > > Entries.record_info # => [ :title => :string, :author => > > [ :one_to_one, :author ] ... etc > > > If someone can point me to where I can reflect on associations, I can > > pull this together. Or maybe I've just missed the right place in the > > API? > > > Tip of the hat, again. Great work. > > > Regards, > > Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to sequel-talk@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---