Replies: 1 comment 3 replies
-
You need to specify |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wrote a ruby application using DataMapper quite a few years ago but a recent O/S upgrade (viz to Ruby 3.2, most notably) broke it... seemingly irremediably (data_objects module not updated for 6+ years?) so... i'm porting to Sequel. I got one of my modules ported, and working... but without certain things, e.g. my working schema is:
`class Album < Sequel::Model
end
class Artist < Sequel::Model
end
`
But this:
`
class Album < Sequel::Model
many_to_one :artists
end
class Artist < Sequel::Model
one_to_many :albums
end
'
Results in the following output:
'listAlbums /home/craig/.local/share/gem/ruby/3.2.0/gems/sequel-5.84.0/lib/sequel/model/associations.rb:2355:in
def_one_to_many': mismatched number of keys: [:artist_id] vs [:id, :name] (Sequel::Error)from /home/craig/.local/share/gem/ruby/3.2.0/gems/sequel-5.84.0/lib/sequel/model/associations.rb:2034:in
def_association' from /home/craig/.local/share/gem/ruby/3.2.0/gems/sequel-5.84.0/lib/sequel/model/associations.rb:1917:in
associate'from /home/craig/.local/share/gem/ruby/3.2.0/gems/sequel-5.84.0/lib/sequel/model/associations.rb:1978:in
one_to_many' from /home/craig/src/ruby/sequel-schema.rb:23:in
class:Artist'from /home/craig/src/ruby/sequel-schema.rb:21:in
<top (required)>' from /usr/local/bin/listAlbums:3:in
require_relative'from /usr/local/bin/listAlbums:3:in `
'
I'm suspecting the problem is in my postgres db table definitions:
`
music=> \d albums
Table "public.albums"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+------------------------------------
id | integer | | not null | nextval('albums_id_seq'::regclass)
artist_id | integer | | not null |
name | character varying(255) | | not null |
path | character varying(255) | | |
bdate | timestamp without time zone | | |
year | integer | | |
artist_name | character varying(255) | | not null |
Indexes:
"albums_pkey" PRIMARY KEY, btree (id, artist_id, name, artist_name)
"index_albums_artist" btree (artist_name)
"unique_albums_key" UNIQUE, btree (id, artist_id, name)
music=> \d artists
Table "public.artists"
Column | Type | Collation | Nullable | Default
--------+------------------------+-----------+----------+-------------------------------------
id | integer | | not null | nextval('artists_id_seq'::regclass)
name | character varying(255) | | not null |
Indexes:
"artists_pkey" PRIMARY KEY, btree (id, name)
'
I didn't (exactly) create those definitions... dataMapper did. I always thought there was something "wrong" with the way it did it... creating an artist_name column in the 'albums' table, when the join i wanted was through 'artist_id'. I'm no db expert, though, so i just used what it gave me. Now, though, i think that may be the source of the problem. But, given one day's familiarity with Sequel, the fact that i wrote this code years ago, and that i myself didn't even create that (irregular?) table definition... i'm over my head as to how to fix the 'mismatched number of keys' error... but... i think the problem is probably quite simply resolved... if only i knew what i was doing. Can anyone enlighten me as to how to proceed. I was not at all familiar with db migrations, but started reading about it. However, for me, i think all i might need to do is go into psql and change a table definition (drop the 'artist_name' column?). I'd like a little more insight, though, before really messing things up. Thanks for any help.
Beta Was this translation helpful? Give feedback.
All reactions