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

it bails out when asked for an empty nested has_many relationship (undefined method `[]' for nil:NilClass) #366

Open
x-yuri opened this issue Jul 22, 2020 · 0 comments · May be fixed by #367
Labels
Enhancement Enhancements to existing features
Milestone

Comments

@x-yuri
Copy link
Contributor

x-yuri commented Jul 22, 2020

When you just created an issue, the attachments relationship is unusable (client.Issue.build.save.attachments gives "undefined method [] for nil:NilClass"). That happens because attachments are nested under fields. And in such case the parent must exist.

Right now I have to do:

attachments = issue.attrs.has_key?('fields') \
  ? issue.attachments \
  : jira.Issue.find(issue.id).attachments
attachments.build.save!(file: p)

Alternatively:

if issue.attrs.has_key?('fields')
  issue.attachments.build.save!(file: p)
else
  JIRA::Resource::Attachment.new(client, issue: issue).save!(file: p)
end

I first tried client.Attachment.build(issue: issue).save!(file: p), but it doesn't work since build()'s arguments are passed down in the attrs key. E.g. initialize() looks in options[:issue], but the relation is in options[:attrs][:issue].

@bobbrodie bobbrodie added the Enhancement Enhancements to existing features label Apr 2, 2024
@bobbrodie bobbrodie added this to the v3.0.0 milestone May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhancements to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants