On Aug 9, 12:16 pm, Jeremy Evans <[email protected]> wrote:
>
> If you just want to keep the changes in the same file as the subclass:
>
> module ACS
> module Media
> ACS::Object.cti_table_map[:"ACS::Media::File"] = :acs_media_files
> class File < ACS::Object
> end
> end
> end
Ah, of course... yep, that works for me...
So now I've hit a bug in either the interaction between the CTI
plugin, UUID primary keys, and the sqlite adapter, or my understanding
of how to handle UUIDs as a datatype in sequel. Plus, for good
measure, a question on the :key option for CTI.
Short form - when using sqlite, after inserting the rows that make up
a new object (with correct uuid-valued id column), sequel tries to
retrieve the complete object back with a query joining the relevant
tables but specifying "where id = 1". This query returns no rows, so
the entire insert is rolled back. Also, in both sqlite and postgres,
the "kind" column specified where I include the CTI plugin isn't being
populated - this is copied straight from the examples so I'm not sure
if the documentation is out of date or if I'm doing something that
breaks it.
I run these migrations, which set up the database as expected -
Sequel.migration do
up do
create_table(:acs_objects) do
column :id, :uuid, :primary_key => true
String :kind #, :null => false
end
end
down do
drop_table(:acs_objects)
end
end
Sequel.migration do
up do
create_table(:acs_media_files) do
foreign_key :id, :acs_objects, :type => :uuid, :key
=> :id, :on_delete => :cascade
String :url, :null => false
end
end
down do
drop_table(:acs_media_files)
end
end
and then require these bits into a sequel session pointing at either a
sqlite3 or postgres database -
require 'sequel'
require 'uuidtools'
module ACS
class Object < Sequel::Model
set_dataset :acs_objects
plugin :class_table_inheritance, :key => :kind
def before_create
self.id ||= UUIDTools::UUID.random_create
end
end
end
class UUIDTools::UUID
def sql_literal(dataset)
dataset.literal_uuid self
end
end
class Sequel::Dataset
def literal_uuid(v)
"'#{v.to_s}'"
end
end
module ACS
module Media
ACS::Object.cti_table_map[:'ACS::Media::File'] = :acs_media_files
class File < ACS::Object
end
end
end
and then try to create an ACS::Media::File object -
>> bleh = ACS::Media::File.create :url => 'http://foo.org/bleh'
I, [2010-08-09T12:35:09.089979 #7613] INFO -- : (0.000175s) SELECT
sqlite_version() LIMIT 1
I, [2010-08-09T12:35:09.090143 #7613] INFO -- : (0.000049s) BEGIN
I, [2010-08-09T12:35:09.091185 #7613] INFO -- : (0.000401s) INSERT
INTO `acs_objects` (`id`) VALUES ('bcb07390-8df0-4cd1-862e-
fd047df9967f')
I, [2010-08-09T12:35:09.091534 #7613] INFO -- : (0.000082s) INSERT
INTO `acs_media_files` (`url`, `id`) VALUES ('http://foo.org/bleh',
'bcb07390-8df0-4cd1-862e-fd047df9967f')
I, [2010-08-09T12:35:09.092016 #7613] INFO -- : (0.000109s) SELECT *
FROM `acs_objects` INNER JOIN `acs_media_files` USING (`id`) WHERE
(`id` = 1) LIMIT 1
I, [2010-08-09T12:35:09.092502 #7613] INFO -- : (0.000372s) ROLLBACK
Sequel::Error: Record not found
from /Library/Ruby/Gems/1.8/gems/sequel-3.14.0/lib/sequel/model/
base.rb:1171:in `_refresh'
... more traceback ...
Which falls over when sequel tries to get a copy of the complete
object back out of the database.
Is this a corner in sequel that has never needed to work before, or am
I just doing something wrong with the UUID PK handling that's
confusing the sqlite adapter?
Many thanks for your help with this.
cheers
Russell
--
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.