Skip to content

Comments

Allow arbitrary project linkage#281

Open
miles-smith wants to merge 18 commits intodevelopfrom
project-relationship-graphs
Open

Allow arbitrary project linkage#281
miles-smith wants to merge 18 commits intodevelopfrom
project-relationship-graphs

Conversation

@miles-smith
Copy link
Contributor

As per request to change project linkage from a parent/child type relationship to a many-to-many relationship.

I think there's more that could be done but let's see how far this gets us to start with...

end

def destroy
@other_project = @project_relationship.projects.detect { |project| project != @project }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a question than anything - would where.not(id: @project.id) be more efficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, and you're absolutely right.

It's still one DB hit, but the difference is in loading one record into memory rather than two. There are times when relying on the preloaded/cached association would be beneficial but this isn't one of those instances :D

This code was a remnant from when associations weren't as fleshed out as they are now and project_relationships.projects was just an enumerable wrapper around the two belongs_to associations.

I'll push a commit with your suggested change 👍

Miles Smith added 2 commits September 14, 2021 09:41
$ Conflicts:
$	app/views/projects/application/_form.html.erb
$	config/locales/en.yml
$	db/structure.sql
$	test/models/project_test.rb
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

Successfully merging this pull request may close these issues.

2 participants