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

has_and_belongs_to_many build is not persising the relationship #752

Closed
jcoyne opened this issue Apr 3, 2015 · 2 comments
Closed

has_and_belongs_to_many build is not persising the relationship #752

jcoyne opened this issue Apr 3, 2015 · 2 comments

Comments

@jcoyne
Copy link
Member

jcoyne commented Apr 3, 2015

class Part < ActiveFedora::Base
end
class Whole < ActiveFedora::Base
  has_and_belongs_to_many :parts, predicate: ::RDF::URI('http://example.com/foo')
end

whole = Whole.create
whole.parts.build
whole.save
whole.reload
whole.parts
# => []

we expect that whole.parts should contain one Part

@jcoyne
Copy link
Member Author

jcoyne commented Apr 4, 2015

It's actually only doing this when you don't have an inverse has_many on the Part model. Perhaps we can raise a warning if you do whole.parts.build and there isn't an inverse relationship.

@jcoyne
Copy link
Member Author

jcoyne commented Apr 4, 2015

Seems like its happening when one of these blocks don't match:
https://github.com/projecthydra/active_fedora/blob/master/lib/active_fedora/associations/has_and_belongs_to_many_association.rb#L21-L28 I suspect is should look more like this.

@jcoyne jcoyne closed this as completed Apr 7, 2015
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

Successfully merging a pull request may close this issue.

1 participant