last day (14 days later) » 

1:21 PM
Hi there.
 
So I'm beginning to think that my tables were never used to begin with.
 
can you tell me more about relation between Images and Products
 
Because I was using has_and_belongs_to_many
So I changed that to has_many for both product and image, and added a through:
 
so a Image also has many products?
 
1:22 PM
Correct.
Now I'm getting:
NoMethodError (undefined method `klass' for nil:NilClass):
 
Have you tried to add touch: :true to the Image model, so it will update all products related to this image
also the callback should be in Image
not ProductImage
hmmm
thinking...
NoMethodError (undefined method `klass' for nil:NilClass): - where this comes from?
 
Image
So this is in Product:
has_many :images, through: :images_products #, :dependent => :delete_all
 
is it ok with you if we do a TeamViewer session?
 
And then in Image:
 
to try things in rails console
 
1:24 PM
Sure
has_many :products, through: :images_products
566 127 959
3764
 
soething is wrong with connection
 
yes
 
So touch didn't work because it wasn't actually using my join tables.
 
so.. do you have Image table now?
you said you rolled back
 
1:32 PM
Because I was using has_and_belongs_to_many
Yes, but migrated back up to the new version, which uses has_many through
 
Let me try one more thing
 
Which is the correct way if you're using a join table.
But now I'm getting another error.
Check the first tab in terminal
 
but how that part is related to your problem? this comes up after you change to has_many_through ?
 
So.
Document is basically the same thing as Image here.
It's just haulting on that first because D becomes before I.
And the line it's giving isn't actually the line that's failing.
It's the has_many
 
you add documents to products, right?
so it's the product first
then document
 
1:43 PM
Yes.
 
product.documents.new should work
 
But they can also exist separately.
So you create them separately.
 
When I created a document somehow it won't allow me
has_many :appointments
has_many :patients, through: :appointments
that means you have to write also the relation between the product and documents_products
it's a must
cause when you say through: :appointments without defining :appointments it will give you an error
 
Had to quite teamviewer here, couldn't type.
quit
I think the problem is that plurals messing with the system.
But apparently this is the correct naming for join tables in ror.
 
I don't think so.. 1 min
need to read the api
 
1:56 PM
They were even created automatically.
Ok.
 
look at the migration from rails guides
class CreateAppointments < ActiveRecord::Migration
def change
create_table :physicians do |t|
t.string :name
t.timestamps
end

create_table :patients do |t|
t.string :name
t.timestamps
end

create_table :appointments do |t|
t.belongs_to :physician
t.belongs_to :patient
t.datetime :appointment_date
t.timestamps
end
end
end
the table name has noting to do with it
 
But when it comes to the models I think it gets confused.
Because I'm saying :documents_products, which should be the plural form, so it removes that to find the model named DocumentsProduct
Right?
Just as it would look for Appointment, when we say through: :appointments
 
yea, document_products would be the appropriate one.. or even better product_documents
 
Let me try changing the model names here.
 
any luck? or you are still in the process of renaming them?
 
2:08 PM
Yeah, got another error, but it's all naming related it seems.
Trying to wrap up before I have to leave. :P
NameError: uninitialized constant Product::DocumentProduct
 
when this is happening?
 
p.documents
Where p is a product.
In Product:
has_many :image_products
has_many :video_products
has_many :document_products
has_many :link_products
has_many :images, through: :image_products #, :dependent => :delete_all
has_many :videos, through: :video_products #, :dependent => :delete_all
has_many :documents, through: :document_products #, :dependent => :delete_all
has_many :links, through: :link_products #, :dependent => :delete_all
And here's the new join table class:
class VideoProduct < ActiveRecord::Base

self.table_name = "products_videos"

self.primary_keys = :product_id, :video_id

belongs_to :product, touch: true
belongs_to :video, touch: true

after_save { product.touch }

def self.belonging_to(product_ids)
belonging = where(product_id: product_ids)
return belonging
end

end
 
that's VideoProduct
 
Same for all of them.
DocumentProduct is:
class DocumentProduct < ActiveRecord::Base

self.table_name = "documents_products"

self.primary_keys = :product_id, :document_id

belongs_to :product, touch: true
belongs_to :document, touch: true

after_save { product.touch }

def self.belonging_to(product_ids)
belonging = where(product_id: product_ids)
return belonging
end

end
Is this a namespace thing?
Why is it doing Product::VideoProduct?
 
it is, but why?
can I have a look at it again in TW?
 
2:12 PM
Yep.
Open now.
 
2:35 PM
Here?
 
yes
have a nice day.. or evening.. not sure what time is there
 
I'll take a look at this later.
Is this chat sticky?
 
yes, it is
 
I'll jump in here later and keep you updated.
 
you just look for the your question and see in comments the link to it
ok
bye
 

last day (14 days later) »