Rails belongs_to with custom column name

Solution 1:

You must use the name of the association, also need to add the foreign key to the belongs_to

# Returns a FamiliaProducto object
p = Producto.first
p.familia_producto

# Producto model
belongs_to :familia_producto, class_name: 'FamiliaProducto', foreign_key: 'familia'

# FamiliaProducto model
has_many :productos, class_name: 'Producto', foreign_key: 'familia'

# Returns an integer
p = Producto.first
p.familia