Skip to content
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

Association attribute writer does not work when association name doesn't match association class #92

Closed
liveh2o opened this issue Jun 17, 2022 · 1 comment

Comments

@liveh2o
Copy link
Owner

liveh2o commented Jun 17, 2022

When defining an association with a name that doesn't match the class, the writer method does not work:

class Job < ActiveRemote::Base
end

class Member < ActiveRemote::Base
  belongs_to :recent_job, :class_name => "Job"
end
2.6.10 :002 > m = Member.new
2.6.10 :002 > m.recent_job = Job.new
 =>  #<Job ... >
2.6.10 :003 > m.recent_job
 => nil
liveh2o added a commit that referenced this issue Jun 17, 2022
Per #92, when defining an association with a name that doesn't match the
class, the writer method does not work:

```
class Author < ActiveRemote::Base
end

class Post < ActiveRemote::Base
  belongs_to :co_author, :class_name => "Author"
end

2.6.10 :002 > post = Post.new
2.6.10 :002 > post.coauthor = Author.new
 =>  #<Author ... >
2.6.10 :003 > post.coauthor
 => nil
```

It turns out this is because the reader method was using the association
name as the instance variable (`@coauthor`), but the writer method was
using the name of the class that was set as the instance variable
(`@author`).

Update the writer method to use the association name for the instance
variable.
@liveh2o
Copy link
Owner Author

liveh2o commented Jun 17, 2022

Resolved by 85b369a.

@liveh2o liveh2o closed this as completed Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant