On Jun 24, 10:50 am, Jeremy Evans <[EMAIL PROTECTED]> wrote:
> On Jun 24, 9:27 am, Glen <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jun 24, 10:16 am, Jeremy Evans <[EMAIL PROTECTED]> wrote:
>
> > > On Jun 24, 8:28 am, Glen <[EMAIL PROTECTED]> wrote:
>
> > > > Is it possible to create a non-integer key with Sequel?
>
> > > Yes.
>
> > > primary_key :name, :type=>:text
> > > foreign_key :artist_name, :artists, :type=>:text
>
> > > Jeremy
>
> > Thanks for the response Jeremy.
>
> > However when I try this:
>
> > class Computers < Sequel::Model
> > set_schema do
> > primary_key :name, :type => :text
> > varchar :os
> > varchar :ip
> > varchar :mac
> > end
> > end
>
> > I get the following error:
>
> > Sequel::Error::InvalidStatement: CREATE TABLE `computers` (`name` text
> > PRIMARY KEY AUTOINCREMENT, `os` text, `ip` text, `mac` text)
> > AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
>
> > I get the same error when I try it this way:
>
> > db = Sequel.sqlite(DB_NAME)
>
> > db.create_table :computers do
> > primary_key :name, :type => :text
> > column :os, :text
> > column :ip, :text
> > column :mac, :text
> > end
>
> Looks like you have to unset the :auto_increment option when using
> primary keys
>
> class Computers < Sequel::Model
> set_schema do
> primary_key :name, :type => :text, :auto_increment => false
> varchar :os
> varchar :ip
> varchar :mac
> end
> end
>
> Give that a shot and see if it works.
>
> Jeremy
Thanks Jeremy that works great!
I suppose I need to do something similar for foreign keys. The
foreign_key method looks like it is hard coded to set the type to
integer.
# File sequel_core/lib/sequel_core/schema/generator.rb, line 77
77: def foreign_key(name, table=nil, opts = {})
78: opts = case table
79: when Hash
80: table.merge(opts)
81: when Symbol
82: opts.merge(:table=>table)
83: when NilClass
84: opts
85: else
86: raise(Error, "The seconds argument to foreign_key should
be a Hash, Symbol, or nil")
87: end
88: column(name, :integer, opts)
89: end
Are there some magic options I can pass to set it to the needed type?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---