Say I have a model of type A and a model of type B that has fields a_id a2_id. I want to have something like:
class B belongs_to :a belongs_to :a (using a2) end
Does anyone know how I will do this? I am trying to use class B to bind similar objects in my DB.
You can do it
class B belongs_to :a belongs_to :a2, foreign_key: 'a2_id', class_name: 'A' end
or even this:
class B < ActiveRecord::Base attr_accessible :a2_id, :a_id, :name belongs_to :a belongs_to :a2, class_name: "A" end
Source: https://habr.com/ru/post/921164/More articles:rich: editor tag doesn't work when it's nested inside rich: popupPanel in JSF with RichFaces 4.2.0 - jsfHow to call a procedure with out parameter as a table type from a Java class - oraclesetting content type for mp4 files on s3 - ruby-on-railsAngularJS direct link function not working - javascriptHow to delete specific records (using regular expression) from an array? - arrayscorrelation values ββin the grants grid from ggplot2 - rIs there a better way to broadcast arrays? - pythonMongoid recursively finds an embedded document - mongodbmatplotlib: using color table for color table - pythonshaded triplet in r - rAll Articles