Hi all

So I have two tables and corresponding models. The primary key charcode in 
table *currencies* is a string. And field *purses.currency* (string also, 
sure) have the foreign key restriction to table *currencies*.
But when I try to connect all this I get error written below.

class Purse < Sequel::Model
  many_to_one  :currency, key: :currency # varchar(24)
  many_to_many :transactions, :join_table => :transactions_purses
end

class Currency < Sequel::Model
  set_primary_key  :charcode # varchar(24)
  one_to_many  :purses, key: :currency
end

# CODE:
purse = Purse.new client_id: rand(1024), is_system: false, tag: FFaker::Food
.meat, currency: 'USD' 
NoMethodError:
   undefined method `pk' for "USD":String

*What do I wrong? Or this is a bug in Sequel?*

Those tables as they seen in postgres database.

=# \d currencies
                                                          Таблица 
"public.currencies"
  Столбец   |             Тип             | Правило сортировки | 
Допустимость NULL |                       По умолчанию                     
   
------------+-----------------------------+--------------------+-------------------+-----------------------------------------------------------
 charcode   | character varying(24)       |                    | not null   
       | 
 numcode    | integer                     |                    |           
        | 
 money_type | currency_type               |                    | not null   
       | 
 amount     | integer                     |                    | not null   
       | 0
 created_at | timestamp without time zone |                    | not null   
       | '2020-04-20 13:41:27.580541'::timestamp without time zone
 updated_at | timestamp without time zone |                    | not null   
       | '2020-04-20 13:41:27.580541'::timestamp without time zone
Индексы:
    "currencies_pkey" PRIMARY KEY, btree (charcode)
    "currencies_numcode_key" UNIQUE CONSTRAINT, btree (numcode)
    "currencies_charcode_index" btree (charcode)
    "currencies_created_at_index" btree (created_at)
    "currencies_money_type_index" btree (money_type)
    "currencies_numcode_index" btree (numcode)
    "currencies_updated_at_index" btree (updated_at)
Ограничения-проверки:
    "total_must_be_zero" CHECK (amount <= 0)
Ссылки извне:
    TABLE "purses" CONSTRAINT "purses_currency_fkey" FOREIGN KEY (currency) 
REFERENCES currencies(charcode)
Триггеры:
    currencies_read_only_fields BEFORE UPDATE OF charcode, numcode, 
money_type ON currencies FOR EACH ROW EXECUTE FUNCTION disable_updates()
    update_currencies_timestamp BEFORE UPDATE ON currencies FOR EACH ROW 
EXECUTE FUNCTION update_timestamp()



=# \d purses
                                                            Таблица 
"public.purses"
  Столбец   |             Тип             | Правило сортировки | 
Допустимость NULL |                       По умолчанию                     
   
------------+-----------------------------+--------------------+-------------------+-----------------------------------------------------------
 id         | bigint                      |                    | not null   
       | generated by default as identity
 is_system  | boolean                     |                    | not null   
       | false
 client_id  | bigint                      |                    |           
        | 
 amount     | integer                     |                    | not null   
       | 0
 status     | purse_status                |                    | not null   
       | 'test'::purse_status
 created_at | timestamp without time zone |                    | not null   
       | '2020-04-20 13:41:28.615454'::timestamp without time zone
 updated_at | timestamp without time zone |                    | not null   
       | '2020-04-20 13:41:28.615454'::timestamp without time zone
 tag        | character varying(128)      |                    | not null   
       | ''::character varying
 currency   | character varying(6)        |                    | not null   
       | 
 address    | character varying(2048)     |                    |           
        | 
 network    | character varying(12)       |                    |           
        | 
Индексы:
    "purses_pkey" PRIMARY KEY, btree (id)
    "purses_address_network_index" UNIQUE, btree (address, network)
    "purses_client_id_currency_tag_index" UNIQUE, btree (client_id, currency
, tag)
    "purses_client_id_index" btree (client_id)
    "purses_created_at_index" btree (created_at)
    "purses_currency_index" btree (currency)
    "purses_status_index" btree (status)
    "purses_updated_at_index" btree (updated_at)
Ограничения-проверки:
    "positive_balance" CHECK (amount >= 0)
    "purses_client_id_check" CHECK (client_id > 0)
Ограничения внешнего ключа:
    "purses_currency_fkey" FOREIGN KEY (currency) REFERENCES currencies(
charcode)
Ссылки извне:
    TABLE "transactions_purses" CONSTRAINT 
"transactions_purses_purse_id_fkey" FOREIGN KEY (purse_id) REFERENCES purses
(id)
Триггеры:
    check_crypta_wallet_have_address BEFORE INSERT ON purses FOR EACH ROW 
EXECUTE FUNCTION crypta_wallet_have_address()
    check_system_is_not_client BEFORE INSERT ON purses FOR EACH ROW EXECUTE 
FUNCTION system_is_not_client()
    purses_read_only_fields BEFORE UPDATE OF client_id, is_system, currency, 
address, network ON purses FOR EACH ROW EXECUTE FUNCTION disable_updates()
    update_purses_timestamp BEFORE UPDATE ON purses FOR EACH ROW EXECUTE 
FUNCTION update_timestamp()



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/510b320b-82b9-4879-aa85-e626382a9319%40googlegroups.com.

Reply via email to