activerecord - Creating and enforcing has_one relationship in rails relational database -
Working on a table of profiles I have an issue to install, is this correct? I am confused about has_many and has_one relations because it is a table with one line for each visited relationship, I have decided to go with has_one
is it correct? Is this also a way to implement the relationship in the ActiveCard?
Model Class ViewProfile & lt; ActiveRecord :: base verifies: seen_profile_id, presence: true is valid: profile_id, presence: true_one: profile_id is_on: seen_profile_id end migration < Code> Create Classviews Profiles & lt; ActiveRecord :: Migration Change Diff change_table: seen_profiles do | T | T.integer: profile_id t.integer: viewed_profile_id end end end edit
with it also when I go to my console and type the profile I've seen So does nothing come in the form of any idea? = C Schema should usually be shown!
First of all, you enter model and attributes (especially foreign key) . In the model, Attributes and Association will be set to Models . You have to set your models in this way
Class ViewProfile & lt; ActiveRecord :: Base_On: Profile & Class Profile & lt; ActiveRecord :: Base is_to: viewed_profile validates: seen_profile_id, presence: true is valid: seen_profile_id, Specification: right end and your related migration files should look like this
Create ClassviewProfile & lt; ActiveRecord :: Migration Change Diff change_table: seen_profiles do | T | T.string: Name End And Class CreateProfile & lt; ActiveRecord :: Migration Change Diff change_table: Profile do | T | P>
Class ViewProfile & lt; ActiveRecord :: base verifies: seen_profile_id, presence: true is valid: profile_id, presence: true_one: profile_id is_on: seen_profile_id end migration < Code> Create Classviews Profiles & lt; ActiveRecord :: Migration Change Diff change_table: seen_profiles do | T | T.integer: profile_id t.integer: viewed_profile_id end end end edit
with it also when I go to my console and type the profile I've seen So does nothing come in the form of any idea? = C Schema should usually be shown!
First of all, you enter model and attributes (especially foreign key) . In the model, Attributes and Association will be set to Models . You have to set your models in this way
Class ViewProfile & lt; ActiveRecord :: Base_On: Profile & Class Profile & lt; ActiveRecord :: Base is_to: viewed_profile validates: seen_profile_id, presence: true is valid: seen_profile_id, Specification: right end and your related migration files should look like this
Create ClassviewProfile & lt; ActiveRecord :: Migration Change Diff change_table: seen_profiles do | T | T.string: Name End And Class CreateProfile & lt; ActiveRecord :: Migration Change Diff change_table: Profile do | T | P>
Comments
Post a Comment