neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Any easy way to have `accepts_nested_attributes_for` in neo4jrb? #1116

Open ProGM opened 8 years ago

ProGM commented 8 years ago

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?

subvertallchris commented 8 years ago

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.

ProGM commented 8 years ago

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

subvertallchris commented 8 years ago

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. :-)

nandre7 commented 7 years ago

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

KieranLafferty commented 6 years ago

Any way to do this now?

mvuk commented 6 years ago

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

cheerfulstoic commented 6 years ago

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

jacek213 commented 5 years ago

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