Thank you. I forgot about the names clash. Changed purses.currency to purses.currency_id.
//DP понедельник, 20 апреля 2020 г., 18:10:59 UTC+3 пользователь Jeremy Evans написал: > > On Monday, April 20, 2020 at 4:53:58 AM UTC-7, Dimitri Pekarovsky wrote: >> >> 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?* >> > > You shouldn't use the same name used for the association as used for one > of the columns in the table. You are passing in currency when creating a > new Purse, and it is expecting the value of currency to be an instance of > Currency, since currency is a many_to_one association. > > You need to either change the column name in your database or change the > association name. > > Thanks, > Jeremy > -- 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/f55881d6-6b46-4f65-825f-9a072fa4b7dc%40googlegroups.com.
