I am trying to create a form to protect a very complex relationship. The models are for the relationship below.
class target & lt; ActiveRecord :: base is_to: goal_status belongs_to: goal_type has_many: users, via: user_goals has_many: user_goals has_many: parent_goals, CLASS_NAME: 'GoalDependency', foreign_key: PARENT_ID has_many: child_goals, CLASS_NAME: 'GoalDependency', foreign_key: child_id has_many: Through children,:: child_goals is_maya: parent, through: parent_goals validates_presence_of: goal_status_id ,: goal_type_id end class GoalDependency & lt; ActiveRecord :: base is_to: parent, CLASS_NAME: 'target', foreign_key: is_to 'PARENT_ID': child, CLASS_NAME: 'target', foreign_key: 'child_id' end
There are many parents who can target, or there may be many children, or both of them have tried to save these relationships and try to use a multiple selection drop down to save the child_id / parent_id, but it does not look like Is because the target_department of the two areas are required The need occurs - ie Bal_aidi and Perent_aidi rail only one set if I child_ids'm saving a set list, but this is PARENT_ID set with the current target and do not visa versa.
I have tried to use accepts_nested_attributes, but I'm not really sure how I can select it with multiple drop-down down downs.
How to reach any direction or direction will be appreciated.
The example of my current look.
.row .col-md-6 = simple_form_for (gool) do | F | - If @target.rors.ei? #error_explanation h2 = "# {pluralize (@ goal.errors.count, 'Error')} is prohibited from being saved:" ul -@goal.errors.full_messages.each | Message | Li = message = f.input: description = f.input: goal_status_id, collection: @goal_statuses, value_method: id, label_method: name, as: selection = f.input: goal_type_id, archive: @goal_types, value_method: Id, Label_method: name, as :: select = f.input: user_ids, collection: @users, as :: select, label: 'assigned to', input_html: {class: 'selected-select', multiple: true}, selected: @ Goal.user_ids = f.input: child_ids, collection: @goals, as :: select, label: 'children's target', input_high: {class: 'selected-select', multiple: true}, selected: @first After examining I was thinking another way to do this, but I am not happy with it. I can divide the concept of dependence into the dependence of parents and dependence of a child and divide them into different models. Then the relationship can be handled differently. See the code below for the child's dependence. class target & lt; ActiveRecord :: Base is_to: goal_status is_to: goal_type has_many: users, through :: user_goals has_many: user_goals has_many: child_goals, class_name: 'GoalChildDependency' has_many: children, through :: child_goals validates_presence_of: goal_status_id ,: goal_type_id end class GoalChildDependency & lt; ActiveRecord :: Base is_to: target is_to: child, class_name: 'target', foreign_key :: child_id end
I have read that rail can not deal with composite keys and mine The case seems to be a case where an overall key is understood.
Anyway, if anyone can know how to do their initial code, which will be great.
It may be that the single target with itself parent_id
column referenced on it Models will be easy to get from where you can
has_many: child_goals, CLASS_NAME: 'target', foreign_key: PARENT_ID
belongs_to: parent_goal Additionally, if you need any kind of childhood model, you can get a single table succession model, in the target table column type < / Code> can add Cildagoal & lt; Follow the analog approach according to the target
and above.
No comments:
Post a Comment