Skip to content

Commit

Permalink
join projects and lists
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 3, 2024
1 parent 6640813 commit ca1e327
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 636 deletions.
12 changes: 7 additions & 5 deletions app/models/list.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class List < ApplicationRecord
validates :url, presence: true

has_many :projects
has_many :list_projects
has_many :projects, through: :list_projects

def to_s
name
Expand Down Expand Up @@ -118,10 +119,11 @@ def parse_readme

def load_projects
readme_links.each do |link|

# find or create project
# create join between project and list
# join holds name, description, category, sub_category

project = Project.find_or_create_by(url: link[:url])
project.sync_async
list_project = list_projects.find_or_create_by(project_id: project.id)
list_project.update(name: link[:name], description: link[:description], category: link[:category], sub_category: link[:sub_category])

end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/list_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ListProject < ApplicationRecord
belongs_to :list
belongs_to :project
end
Loading

0 comments on commit ca1e327

Please sign in to comment.