Hi Everyone (but mostly Jeremy from the looks of things?),
I've been working on upgrading the version of Sequel our app uses, and I've
come across a bug I'm having trouble breaking apart. Here's the error I get:
E, [2014-05-12T15:58:09.183705 #88865] ERROR -- : mismatched number of
composite keys: [:deal_id] vs [] (Sequel::Error)
/Users/cf5455/repos/bento/vendor/bundle/ruby/1.9.1/gems/sequel-3.35.0/lib/sequel/model/associations.rb:1264:in
`def_one_to_many'
/Users/cf5455/repos/bento/vendor/bundle/ruby/1.9.1/gems/sequel-3.35.0/lib/sequel/model/associations.rb:917:in
`associate'
/Users/cf5455/repos/bento/vendor/bundle/ruby/1.9.1/gems/sequel-3.35.0/lib/sequel/model/associations.rb:975:in
`one_to_many'
/Users/cf5455/repos/bento/app/models/deal.rb:16:in `<class:Deal>'
/Users/cf5455/repos/bento/app/models/deal.rb:1:in `<top (required)>'
/Users/cf5455/repos/bento/init.rb:29:in `require'
/Users/cf5455/repos/bento/init.rb:29:in `block in <top (required)>'
It pops up in 3.35.0 and persists through 4.12. No problems running 3.34.1.
The classes involved are, thankfully, short:
deal.rb (Line 16, as mentioned in the trace, is one_to_many :vouchers)
class Deal < Sequel::Model(:md_deals)
plugin :validation_helpers
# Database schema:
# user voucher deal
merchant
#
---------------------------------------------------------------------------------
# :cid :id
# :id -------> :user_id
# :deal_id ------->
:id
# :barcode :merchant_id ---------------->
:id
# :state :merchant_location_id ------->
:location_id
# :
#
many_to_one :merchant
one_to_many :vouchers
def self.get_by_user_id user_id
barcodes = Voucher.select(:id, :barcode, :state, :title
).filter(:user_id => user_id)
end
def to_json *a
values.to_json *a
end
end
voucher.rb
class Voucher < Sequel::Model(:md_vouchers)
# LIMIT = 10
plugin :validation_helpers
# Database schema:
# user voucher deal
merchant
#
---------------------------------------------------------------------------------
# :cid :id
# :id -------> :user_id
# :deal_id ------->
:id
# :barcode :merchant_id ---------------->
:id
# :state :merchant_location_id ------->
:location_id
# :
# many_to_one :user
many_to_one :deal
def self.find_all_by_user_id user_id
Voucher.filter(:user_id => user_id).all
end
def to_json *a
values.to_json *a
end
end
To head off some of the more obvious problems:
md_deals is an alias to MYDEALS.DEALS
md_vouchers is an alias to MYDEALS.VOUCHERS
MYDEALS.VOUCHERS has a column called DEAL_ID that is not nullable and of
type NUMBER(10)
MYDEALS.DEALS has a column called ID that is also not nullable and of type
NUMBER(10)
We run tests by creating an equivalent schema to the Oracle DB in SQLite.
Everything runs fine under SQLite. However, I do see that instead of
creating aliases for these tables in the shadow schema, we simply create a
table called md_deals and one called md_vouchers. Is it possible that the
aliasing we're doing is what's breaking it? I looked over the release notes
for 3.35, but I didn't see any changes that looked like probable causes.
Thanks in advance for your help. Let me know if I've left out something
you'd find helpful, and I'm happy to go into more detail.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.