This is my first time on ruby-forum so pardon if this is not posted
correctly.
I am having a very similar issue regarding has_many through has_many. A
logged user can create a work order and associated fields in models name
alias and sub_tasks. I am using active_admin and an admin user can view
and edit the above mentioned models, but when admin tries to create a
sub_task I can get the following error:
Cannot modify association 'WorkOrder#sub_tasks' because the source
reflection class 'SubTask' is associated to 'NameAlias' via :has_many.
the models:
class work_order < ActiveRecord::Base
has_many :name_aliases
has_many :sub_tasks, :through => :name_aliases
end
class NameAlias < ActiveRecord::Base
belongs_to :work_order
has_many :sub_tasks
end
class SubTask < ActiveRecord::Base
belongs_to :name_alias
belongs_to :work_order
end
A pervious post mentioned a solution using an after_save method before
declaring the association... but I didn't see sample code? since i am
new to rails it would be helpful to see or example how this can be
resolved. Thanks for your help!
This produced a "Unknown key: through" error? Not sure I place the
association in the correct model, I have attached a file for reference.
I appreciate your help!
By the way, in the attachment you have multiple default scopes for
WorkOrder. I think only one is allowed. You can order by multiple
fields in one scope of course if that is what you want. Be careful
with specifying the order in default scope though, it is not possible
to override this (or at least it did not used to be possible) as the
default scope order is applied *after* any others.
of the is post.
accepts_nested_attributes_for :name_alias
accepts_nested_attributes_for :work_order
This produced a "Unknown key: through" error? Not sure I place the
association in the correct model, I have attached a file for reference.
I appreciate your help!
By the way, in the attachment you have multiple default scopes for
WorkOrder. I think only one is allowed. You can order by multiple
fields in one scope of course if that is what you want. Be careful
with specifying the order in default scope though, it is not possible
to override this (or at least it did not used to be possible) as the
default scope order is applied *after* any others.
Colin
Thanks, make sense regarding default scope... still getting the error?
wired, that a logged user can create and edit sub_task, but admin user
via acitve_admin can edit but no create a sub_task?
Do you/available for consulting/help with a projects? if so, how does it
work? per hour, etc..
of the is post.
accepts_nested_attributes_for :name_alias
accepts_nested_attributes_for :work_order
This produced a "Unknown key: through" error? Not sure I place the
association in the correct model, I have attached a file for reference.
I appreciate your help!
By the way, in the attachment you have multiple default scopes for
WorkOrder. I think only one is allowed. You can order by multiple
fields in one scope of course if that is what you want. Be careful
with specifying the order in default scope though, it is not possible
to override this (or at least it did not used to be possible) as the
default scope order is applied *after* any others.
Colin
Thanks, make sense regarding default scope... still getting the error?
Is that a question? Did you add the id column to the table and run
the migration?
Show us the complete error message and stack trace and the section of
your code that is causing it.
wired, that a logged user can create and edit sub_task, but admin user
via acitve_admin can edit but no create a sub_task?
It is executing different code or with different data and causing the
error. Nothing weird about it.
Do you/available for consulting/help with a projects? if so, how does it
work? per hour, etc..
of the is post.
accepts_nested_attributes_for :name_alias
accepts_nested_attributes_for :work_order
This produced a "Unknown key: through" error? Not sure I place the
association in the correct model, I have attached a file for reference.
I appreciate your help!
By the way, in the attachment you have multiple default scopes for
WorkOrder. I think only one is allowed. You can order by multiple
fields in one scope of course if that is what you want. Be careful
with specifying the order in default scope though, it is not possible
to override this (or at least it did not used to be possible) as the
default scope order is applied *after* any others.
Colin
Thanks, make sense regarding default scope... still getting the error?
Is that a question? Did you add the id column to the table and run
the migration?
What am I talking about? That was someone else in a different thread.
Ignore the id comment.