New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model.new returning a pre-initialised object in class method #35666
Comments
Could you create a reproduction script with this template https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_master.rb? |
Went ahead and created a template for you @sonal425chouhan https://gist.github.com/andrehjr/efda765d33883489d01ab603f7613047#file-issue35666-rb What's happening is that when you call a 'class' method on a ActiveRecord::Relation. It creates a 'scope'. When you call See: A "quick fix" would be to calling |
This issue has been automatically closed because there has been no follow-up response from the original author. We currently don't have enough information in order to take action. Please reach out if you have any additional information that will help us move this issue forward. |
IMO, initializing objects like this with scope attributes sounds legit, but the scope attributes shouldn't include primary key |
Steps to reproduce
def self.set_new_project
Project.new
end
Expected behaviour
This should return an uninitialised object i.e
<Project id: nil, name: nil, description: nil>
Actual behaviour
It returns an id initialised object i.e
<Project id: 1, name: nil, description: nil>
Additional Information:
Project.new.reload
in set_new_project then it will return an object with all fields initialised as that of 'a'Project.all
then it will return aSystem configuration
Rails version:
Rails 5.2.0.rc1
Ruby version:
2.4.2
The text was updated successfully, but these errors were encountered: