You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was unable to create a record in my Sale model. Then I found that it's because I have a relationship named client and I think it's collisioning with Airrecord::Table.client.
This is the problem:
classSale < Airrecord::Tableself.base_key=ENV['AIRTABLE_BASE_ID']self.table_name='Venta'belongs_to:client,class: "Client",column: "Cliente"endSale.create('Notas'=>'hola')NoMethodError: undefinedmethod`connection' for nil:NilClassfrom /Users/juanjo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/airrecord-1.0.7/lib/airrecord/table.rb:153:in `create'
Is this the actual error? What are the alternatives for a fix? (I work on a solution with guidance, would be my first time) Can we document client is reserved?
The text was updated successfully, but these errors were encountered:
jjercx
changed the title
Problem with client
Problem with client on create
Aug 12, 2021
jjercx
changed the title
Problem with client on create
Problem with client association on create
Aug 12, 2021
yes, your belongs_to is clashing with Airrecord client class method. Probably it would be better to raise a warning message or an exception when defining the belongs_to method here, if an Airrecord method is being overriden:
defhas_many(method_name,options)safely_define_method(method_name.to_sym)do# Get association ids in reverse order, because Airtable's UI and API# sort associations in opposite directions. We want to match the UI.ids=(self[options.fetch(:column)] || []).reversetable=Kernel.const_get(options.fetch(:class))returntable.find_many(ids)unlessoptions[:single](id=ids.first) ? table.find(id) : nilendsafely_define_method("#{method_name}=".to_sym)do |value|
self[options.fetch(:column)]=Array(value).map(&:id).reverseendenddefsafely_define_method(method_name, &block)# Warn if method existsifmethod_defined?(method_name)warn"#{self.name}: overriding method '#{method_name}'!"endendsend(:define_method,method_name, &block)end
Note I haven't tested this implementation. What do you think @sirupsen ?
I was unable to create a record in my
Sale
model. Then I found that it's because I have a relationship namedclient
and I think it's collisioning with Airrecord::Table.client.This is the problem:
But it works if I comment the relationship:
Is this the actual error? What are the alternatives for a fix? (I work on a solution with guidance, would be my first time) Can we document
client
is reserved?The text was updated successfully, but these errors were encountered: