Follow up on my last email to Lars. A few spelling mistakes were in my
modified code. I took some time to consolidate what I meant, made some
changes (like sqlite in-memory, removed lot of self, and moved most of
the logic inside the models).
Enjoy!
require 'rubygems'
require 'logger'
require 'sequel'
DB = Sequel.sqlite(:loggers => Logger.new($stdout))
class Foo < Sequel::Model
one_to_many :bars
plugin :association_dependencies, :bars => :delete
plugin :schema
set_schema do
primary_key :id
text :s1
text :s2
end
create_table unless table_exists?
end
class Bar < Sequel::Model
many_to_one :foo
plugin :schema
set_schema do
primary_key :id
text :s1
integer :i1
foreign_key :foo_id
end
create_table unless table_exists?
end
Foo << { :s1 => 'foo_1', :s2 => 'foo_1' }
Foo[1].add_bar :s1 => 'bar_1', :i1 => 1
Foo[1].add_bar :s1 => 'bar_2', :i1 => 2
Foo[1].add_bar :s1 => 'bar_3', :i1 => 3
Foo[1].add_bar :s1 => 'bar_4', :i1 => 4
puts Foo.count
puts Bar.count
Foo[1].destroy
puts Bar.count
--
Christian
--
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.