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

Does cocoon work with self-joins? #634

Open
ITS-Marcelo opened this issue Jan 21, 2025 · 1 comment
Open

Does cocoon work with self-joins? #634

ITS-Marcelo opened this issue Jan 21, 2025 · 1 comment

Comments

@ITS-Marcelo
Copy link

I'm having troubles understanding if cocoon can work with self-joins. I have the following setup:

class Project < ApplicationRecord
  has_many :allowed_items, class_name: "Project", foreign_key: "validator_id", inverse_of: :validator
  belongs_to :validator, class_name: "Project", inverse_of: :allowed_items, optional: true
  accepts_nested_attributes_for :allowed_items, allow_destroy: true

When I try to create a new project and make it have a validator_id of a per-existing project, I get the following error:

SQLite3::ConstraintException: NOT NULL constraint failed: projects.name

This is where I'm getting confused, from looking at the debug logs, it looks like a project is created with the name and target "s" (sorry for my lack of originality in naming). But then a second project is attempted to be created and fails due to not having a name or target specified. The logs specify that a validator_id was given through the form and it value is 131. The second project item that is attempted to be created has also has a validator_id assigned of value 217 (which I am assuming it is the recently created project). However, I don't want to create two projects. I want to create a project and associated to an existing project. I'll include the log message below:

Started POST "/projects" for 127.0.0.1 at 2025-01-21 10:29:39 -0800
Processing by ProjectsController#create as HTML
  Parameters: {"authenticity_token"=>"[FILTERED]", "project"=>{"name"=>"s", "target"=>"s", "allowed_items_attributes"=>{"1737484178511"=>{"validator_id"=>"131", "_destroy"=>"false"}}}, "commit"=>"Create Project"}
  TRANSACTION (0.0ms)  begin transaction
  ↳ app/controllers/projects_controller.rb:44:in `block in create'
  Project Create (0.5ms)  INSERT INTO "projects" ("name", "target", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["name", "s"], ["target", "s"], ["created_at", "2025-01-21 18:29:39.164287"], ["updated_at", "2025-01-21 18:29:39.164287"]]
  ↳ app/controllers/projects_controller.rb:44:in `block in create'
  Project Create (0.3ms)  INSERT INTO "projects" ("created_at", "updated_at", "validator_id") VALUES (?, ?, ?)  [["created_at", "2025-01-21 18:29:39.166303"], ["updated_at", "2025-01-21 18:29:39.166303"], ["validator_id", 217]]
  ↳ app/controllers/projects_controller.rb:44:in `block in create'

Any feedback would appreciated. Cheers.

@nathanvda
Copy link
Owner

In the posted params we see 1 project (to be created) with one allowed-item, also to be created.

So it attempts to create an allowed_item which is a Project, but the "allowed-item" has no name, and for a Project a name is required.

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

2 participants