This is working fine, but I want to add a different behaviour to it.
I want a USER to also have the ability to set an original AUTHOR to the
content of his POST.
In other words, a POST belongs to a USER (submitter who’s posting some
content) and also belongs to an original AUTHOR(a person who’s post
content
is originaly from).
A new model AUTHOR would solve this problem easily. But the issue is
that
the AUTHORS table would have the same exact data as the USERS table.
This is because all of my USERS, are also considered AUTHORS. And that
being said, I shouldn’t really have a new model called AUTHORS cose it
would be a duplicate.
I need a way to refer to the USERS table as AUTHORS as well. So USER 1
is
also an AUTHOR 1. All living in the same table.
Thought about polymorphic associations but after a whole day of
researches
I am not convniced that this is the correct aproach to it. And if it is,
how would that be done.
I thank you in advance for any considerations on this subject. Please
let
me know if there is any other code you need to visualize in order to
come
up with a solution path.
I have two different models. USERS and POSTS.Untill the present moment I
have a pretty straight forward relationship between them.
I want a USER to also have the ability to set an original AUTHOR to the
content of his POST.
In other words, a POST belongs to a USER (submitter who’s posting some
content) and also belongs to an original AUTHOR(a person who’s post content
is originaly from).
Not an odd request at all
You want to look online for “rails self referential associations”
But essentially, in your User model add:
belongs_to :author, :class_name => “User”
and add a migration for the author_id field to be added to the users
table.
You want to look online for “rails self referential associations”
But essentially, in your User model add:
belongs_to :author, :class_name => “User”
and add a migration for the author_id field to be added to the users table.
I think one of us (maybe more!) has misinterpreted what Marcos wanted.
I think he wants to do that on Posts, not Users. That way, each User
can post Posts from many different Authors, rather than each User
being able to attribute things to only one Author ever.