On Nov 25, 4:36 am, morten <[EMAIL PROTECTED]> wrote:
> It might be that I have misunderstood something about using
> Sequal::Migration, but this should work:
>
> ------------START-----------------------------------
> class CreateBusinessprocess < 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
>       integer :waiting
>       integer :processing
>
>       primary_key :id
>       foreign_key :bp_id, :table => :bps
>     end
>   end
> end
>
> class Bp < Sequel::Model
>   one_to_many :statistics
> end
>
> class Statistic < Sequel::Model
>   many_to_one :bp
> end
> ------------------END------------------------------------
>
> But this do!!!
>
> ------------------START -----------------------------
> class Bp < Sequel::Model
>    set_schema do
>       primary_key :id
>       text :name
>     end
>   one_to_many :statistics
> end
>
> class Statistic < Sequel::Model
>    set_schema do
>       primary_key :id
>       integer :waiting
>       foreign_key :bp_id, :table => :bps
>   end
>   many_to_one :bp
> end
> -------------------END------------------------------------
>
> I have checked the DDL from both schema generations, they are
> identical. Using migrations however associations will fail:
>
> ------------------START------------------------------------
> /usr/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_model/record.rb:
> 153:in `pk': No primary key is associated with this model
> (Sequel::Error)
>         from /usr/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_model/
> record.rb:356:in `add_associated_object'
>         from /usr/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_model/
> associations.rb:275:in `add_statistic'
>         from /home/morten/projects/rubyworkspace/main/Sinatra/db_helper.rb:73
>         from /home/morten/projects/rubyworkspace/main/Sinatra/db_helper.rb:
> 70:in `times'
>         from /home/morten/projects/rubyworkspace/main/Sinatra/db_helper.rb:70
> --------------------END----------------------------------------
>
> Hopefully there is a typo in here somewhere, but I can't find it....
> Help and suggestions are very welcome!

There are a couple of issues here.  First is that it appears as though
the tables already exist in the database, otherwise it wouldn't work
in the second case.  If the tables already exist in the database,
there are no need for migrations or set_schema.  If the tables didn't
already exist, then neither method should work, since set_schema does
nothing by itself and the migrations aren't being run (they are just
defined).  Second, you need to post all of your code, otherwise it is
difficult to help.  I can see from the traceback that you are calling
add_statistic, but that call isn't in the code you posted.  Try to
produce the simplest complete example that shows the failure.

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