ancestry gem creating and editing people view forms

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ancestry gem creating and editing people view forms

fugee ohu
I wanna create and edit people but ancestry only provides for one parent_id so how can i have two on a form

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ancestry gem creating and editing people view forms

Nielson Rolim

I'd suggest you create your own solution without ancestry.

I had a similar problem. I have an User model and each user must has one or more parents and one or more children. So I created a join table called users_parents with two attributes user_id and parent_id. In my User model I added to has_and_belongs_to_many entries:

has_and_belongs_to_many :parents, class_name: User, join_table: :users_parents, foreign_key: :user_id, association_foreign_key: :parent_id

has_and_belongs_to_many :children, class_name: User, join_table: :users_parents, foreign_key: :parent_id, association_foreign_key: :user_id

That way, I can add an user as parent of several users or an user as child of several users.

my_user.parents will return all my_user parents and my_user.children will return all my_user children

--
Nielson Rolim
[hidden email]
On 23/09/2018 08:06, fugee ohu wrote:
I wanna create and edit people but ancestry only provides for one parent_id so how can i have two on a form
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/13d9d76c-4f7f-7514-97a6-1c2a18c148f0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ancestry gem creating and editing people view forms

fugee ohu


On Sunday, September 23, 2018 at 10:44:50 AM UTC-4, Nielson Rolim wrote:

I'd suggest you create your own solution without ancestry.

I had a similar problem. I have an User model and each user must has one or more parents and one or more children. So I created a join table called users_parents with two attributes user_id and parent_id. In my User model I added to has_and_belongs_to_many entries:

has_and_belongs_to_many :parents, class_name: User, join_table: :users_parents, foreign_key: :user_id, association_foreign_key: :parent_id

has_and_belongs_to_many :children, class_name: User, join_table: :users_parents, foreign_key: :parent_id, association_foreign_key: :user_id

That way, I can add an user as parent of several users or an user as child of several users.

my_user.parents will return all my_user parents and my_user.children will return all my_user children

--
Nielson Rolim
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="I4Yka6moCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nielso...@...
On 23/09/2018 08:06, fugee ohu wrote:
I wanna create and edit people but ancestry only provides for one parent_id so how can i have two on a form
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="I4Yka6moCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonrails-ta...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="I4Yka6moCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

Thanks What's the difference between that and has_many through approach?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7d11a65d-07f8-49c4-880f-7dffa0326ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ancestry gem creating and editing people view forms

Nielson Rolim

In my case, I didn't need any additional attribute in my join table. So I user has_and_belongs_to_many. If you need additional attributes in you join table, you should create a model for it and use has_many through

https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association

--
Nielson Rolim
[hidden email]
On 29/09/2018 11:21, fugee ohu wrote:


On Sunday, September 23, 2018 at 10:44:50 AM UTC-4, Nielson Rolim wrote:

I'd suggest you create your own solution without ancestry.

I had a similar problem. I have an User model and each user must has one or more parents and one or more children. So I created a join table called users_parents with two attributes user_id and parent_id. In my User model I added to has_and_belongs_to_many entries:

has_and_belongs_to_many :parents, class_name: User, join_table: :users_parents, foreign_key: :user_id, association_foreign_key: :parent_id

has_and_belongs_to_many :children, class_name: User, join_table: :users_parents, foreign_key: :parent_id, association_foreign_key: :user_id

That way, I can add an user as parent of several users or an user as child of several users.

my_user.parents will return all my_user parents and my_user.children will return all my_user children

--
Nielson Rolim
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="I4Yka6moCgAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" moz-do-not-send="true">nielso...@...
On 23/09/2018 08:06, fugee ohu wrote:
I wanna create and edit people but ancestry only provides for one parent_id so how can i have two on a form
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="I4Yka6moCgAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" moz-do-not-send="true">rubyonrails-ta...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="I4Yka6moCgAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" moz-do-not-send="true">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" onclick="this.href='https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" moz-do-not-send="true">https://groups.google.com/d/msgid/rubyonrails-talk/b628326b-66ee-4f50-afb6-a238d2a0766f%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" moz-do-not-send="true">https://groups.google.com/d/optout.

Thanks What's the difference between that and has_many through approach?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7d11a65d-07f8-49c4-880f-7dffa0326ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2ec898cf-8c74-18d1-5620-2a9737ea7c11%40gmail.com.
For more options, visit https://groups.google.com/d/optout.