activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

Any easy way to have `accepts_nested_attributes_for` in neo4jrb?

Open ProGM opened this issue 9 years ago • 8 comments

I tried the "monkey way":

class Article
  include Neo4j::ActiveNode
  include ActiveRecord::NestedAttributes
  has_many :out, :quotings, rel_class: :QuotingRel
  accepts_nested_attributes_for :quotings
end

But it crashes with a block in accepts_nested_attributes_for': undefined method _reflect_on_association

Any easy solution to have nested attributes in neo4jrb?

ProGM avatar Jan 20 '16 16:01 ProGM

The easiest way would be to hack in our own implementation of this method with a signature matching ActiveRecord's. I can think of an easy enough way to do it, having that class method register the lesson_attributes method in such a way that it will delegate correctly during mass-assignment.

Alternatively, we could use this as motivation to start adapting our own versions of the ActiveRecord::Reflection and ActiveRecord::NestedAttributes public interfaces to not only provide this method but compatibility with gems that rely on them. This is something we've needed for a while but not so crucial that it needs to happen immediately, so I'd weigh the cost of a "hack-it-in-and-make-it-work" implementation VS a Neo4jrb-flavored implementation of complicated interfaces from ActiveRecord.

subvertallchris avatar Jan 20 '16 18:01 subvertallchris

I checked a bit. It seems like ActiveRecord::NestedAttributes is strictly linked to AutosaveAssociation and Reflection, so I would need to implement both.

If I'll get some time, I'll try to

ProGM avatar Jan 22 '16 13:01 ProGM

Yeah, I checked this out back in September 2014 and came to the same conclusion. At the time, I implemented a really basic Reflection class, https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_node/reflection.rb, but I think I'd approach it differently now. We ended up getting our original implementation of association_cache from that experiment but I ultimately had to back off, it was just too much for me back then.

Let me know if I can help. I'm happy to pitch in with this. Now that the ActiveAttr thing is done, I need a new task. :-)

subvertallchris avatar Jan 22 '16 16:01 subvertallchris

Then no way to use gems like cocoon with neo4j.rb or create dynamic nested form in an easy way ?

Alternatively, we could use this as motivation to start adapting our own versions of the ActiveRecord::Reflection and ActiveRecord::NestedAttributes public interfaces to not only provide this method but compatibility with gems that rely on them

nandre7 avatar Oct 15 '16 22:10 nandre7

Any way to do this now?

KieranLafferty avatar Apr 30 '18 07:04 KieranLafferty

Is this planned to be implemented? Is there a substitute way to do this documented anywhere?

mvuk avatar May 11 '18 04:05 mvuk

Sorry for the delay. No current plans to do this. I'd should be able to look over a PR, though.

cheerfulstoic avatar May 20 '18 00:05 cheerfulstoic

@cheerfulstoic so what's the recommended way of saving a model along with multiple associated objects?

jacek213 avatar Jan 18 '19 12:01 jacek213