Super scaffolding makes some incorrect assumptions about naming
jagthedrummer opened this issue · 2 comments
I first user super scaffolding to create a Task
model:
rails g super_scaffold Task Team name:text_field
Then I want to make it so that a Task
can be assigned to many Membership
s under the name assigned_to_memberships
. (Just using memberships
won't work because I also want to have an approvable_by_memberships
relationship that also points to the Membership
model.)
I tried generating a join model by doing this:
rails generate super_scaffold:join_model Tasks::Assignment assigned_to_membership_id{class_name=Membership} task_id{class_name=Task}
That results in Task
getting updated with these lines:
has_many :assignments, class_name: "Tasks::Assignment", dependent: :destroy
has_many :memberships, through: :assignments
But I would expect it to be more like this given the names that I'm using:
has_many :assignments, class_name: "Tasks::Assignment", dependent: :destroy
has_many :assigned_to_memberships, class_name: "Membership", through: :assignments
It also generates a valid_tasks
method in Tasks::Assignment
that is defined like this:
def valid_tasks
membership.valid_tasks
end
But the Membership
model was not updated to have a valid_tasks
method. And again, based on the naming that I'm using I'd expect it to be assigned_to_memberships.valid_tasks
.
Just trying to look into this and it looks like this line in the JoinModelScaffolder
is what's responsible for getting the has_many
declaration wrong.
I think the problem is probably related to the fact that the Scaffolding::ClassNamesTransformer
only deals with model/class names and doesn't account for the fact that a relationship might use different names.