On 30 maalis, 17:05, Jeremy Evans <[email protected]> wrote:
> The primary_key method sets up auto incrementing (surrogate) keys.  To
> use a single natural primary key, you want the :primary_key option:
>
>   class Foo < Sequel::Model
>     set_schema do
>       String :title, :text => :true, :primary_key => true
>     end
>     create_table?
>   end
>
> For composite natural primary keys, you pass the primary_key method an
> array:
>
>   class Foo < Sequel::Model
>     set_schema do
>       String :title, :text => :true
>       String :blah, :text => :true
>       primary_key [:title, :blah]
>     end
>     create_table?
>   end
>
> Jeremy

Thanks for the quick reply. However, changing the schema thusly:

class Foo < Sequel::Model
  set_schema do
    String :title, :primary_key => true, :text => true
  end
  create_table

  one_to_many :bars
end

class Bar < Sequel::Model
  set_schema do
    String :name, :primary_key => true, :text => true
    foreign_key :foo_title, :foos, :text => true
  end
  create_table

  many_to_one :foo, :key => :foo_title, :text => true
end

Foo.insert(:title => 'Baz')
Foo.first.bars.sql

Still produces the following query: SELECT * FROM `bars` WHERE
(`bars`.`foo_id` = 'Baz')

-- 
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.

Reply via email to