On Nov 25, 11:38 pm, morten <[EMAIL PROTECTED]> wrote:
> Crap... I pasted the wrong example. Here is the one with Migration
> that doesn't work.
> -----------------------------------------------
> require 'rubygems'
> require "sequel"
> require "logger"
>
> DB = Sequel.sqlite '', :logger => [Logger.new($stdout)]
>
> class CreateBp < Sequel::Migration
>   def up
>     create_table :bps do
>       primary_key :id
>       text :name
>     end
>   end
> end
>
> class CreateStatistic < Sequel::Migration
>   def up
>     create_table :statistics do
>       primary_key :id
>       foreign_key :bp_id, :table => :bps
>       integer :waiting
>     end
>   end
> end
>
> class Bp < Sequel::Model
>   one_to_many :statistics
> end
>
> class Statistic < Sequel::Model
>   many_to_one :bp
> end
>
> CreateBp.apply(DB, :up)
> CreateStatistic.apply(DB,:up)

Here is your problem.  You are applying the migrations after defining
your model classes.  That's a no-no.  Apply the migrations first, and
things work fine.

> bp = Bp.create(:name => "Order")
>   statistic = Statistic.create(:waiting => rand*100)
>    bp.add_statistic(statistic)
>
> bp.statistic.each do |stat|
>   puts "stat: " + stat[:waiting].to_s
> end

That should be bp.statistics.each do |stat|

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

Reply via email to