Rails. ActiveRecord. Association?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
There is a table Images. How to make Association Images yourself using migration? How to call additional linking table? What to prescribe in the Image model?
by | 11 views

1 Answer

0 like 0 dislike
Everything is now understood.
Create table image_diff (for example).
fields: image_id, second_image_id, percent
Class ImageDiff:
belongs_to :image
belongs_to :second_image, :class_name => "Image", :foreign_key => "second_image_id"
Class Image:
has_one :image_diff # communicate one-to-one, because first_image_id attached to the Image model
you can contact:
im = Image.first
im.image_diff.second_image # here it displays all the connections, so will need to sort out them one by one

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
28,013 users