Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super scaffolding makes some incorrect assumptions about naming #1508

Open
jagthedrummer opened this issue May 31, 2024 · 2 comments
Open

Super scaffolding makes some incorrect assumptions about naming #1508

jagthedrummer opened this issue May 31, 2024 · 2 comments

Comments

@jagthedrummer
Copy link
Contributor

jagthedrummer commented May 31, 2024

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 Memberships 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.

@jagthedrummer
Copy link
Contributor Author

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.

https://github.com/bullet-train-co/bullet_train-core/blob/9b7f280d3a981b11f8f925e946ebff4c1d029436/bullet_train-super_scaffolding/lib/bullet_train/super_scaffolding/scaffolders/join_model_scaffolder.rb#L84

@jagthedrummer
Copy link
Contributor Author

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.

https://github.com/bullet-train-co/bullet_train-core/blob/9b7f280d3a981b11f8f925e946ebff4c1d029436/bullet_train-super_scaffolding/lib/scaffolding/class_names_transformer.rb#L1-L8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant