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
11 views
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.
\r
Create table image_diff (for example).
\r
fields: image_id, second_image_id, percent
\r
Class ImageDiff:
belongs_to :image
belongs_to :second_image, :class_name => "Image", :foreign_key => "second_image_id"
\r
Class Image:
has_one :image_diff # communicate one-to-one, because first_image_id attached to the Image model
\r
you can contact:
im = Image.first
\r
im.image_diff.percent
im.image_diff.second_image # here it displays all the connections, so will need to sort out them one by one
by

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
0 comments
28,013 users