I create a association between two table 'Project' and 'Price'. In their respective model I wrote
class Project < ActiveRecord::Base
validates :name, :tagline, presence: true
has_many :prices
end
..and
class Price < ActiveRecord::Base
belongs_to :project, :foreign_key => 'project_id'
end
But when I check in rails console, example
=> project = Project.last
=> project.prices
It is showing following error
=> #<ActiveRecord::Associations::CollectionProxy []>
..and
=>project.prices.count
=>0
Is anything missing?? Thanks in advance
This is not a error. According to Rails dicumentation it is
"...middlemen between the object that holds the association, known as the @owner, and the actual associated object, known as the @target..."
http://edgeapi.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments