Rails 模型协会的困惑

发布于 2024-12-04 03:44:13 字数 192 浏览 1 评论 0原文

我正在构建一个应用程序(用于学习 Rails),它允许公司/(个人)创建一个个人资料页面来列出他们的员工和技能,以便我网站的用户能够根据技能找到人员,以便他/她可以雇用他们作为合同工一段时间。

我有这些模型公司、员工、技能、合同,但我对如何在这些模型之间建立关联来完成我想要的事情感到困惑。

有没有类似的开源项目存在,以便我可以从中学习。

I am building a app(to learn rails) which allows companies/(individuals too) to create a profile page to list their employees and skills so a user to my site able to find people based on the skill so he/she can hire them as a contract employee for a period of time.

I have these models company,employee,skill,contract but i am confused about how to make associations between these models to do what i want.

Is there any open source projects similar to this exist so i can learn from it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随波逐流 2024-12-11 03:44:13

听起来你需要:

class Company < ActiveRecord::Base
  has_many :employees
end

class Employee < ActiveRecord::Base
  has_many :employeeskills
  has_many :skills, :through => :employeeskills
  belongs_to :company
  has_many :contracts
end

class Skill < ActiveRecord::Base
  has_many :employeeskills
  has_many :employees, :through => :employeeskills
end

class Employeeskill < ActiveRecord::Base
  belongs_to :employee
  belongs_to :skill
end

class Contract < ActiveRecord::Base
  belongs_to :employee
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :contracts
end

然后你可以要求 @user.contracts@employee.skills 等。

希望有帮助!

Sounds like you need:

class Company < ActiveRecord::Base
  has_many :employees
end

class Employee < ActiveRecord::Base
  has_many :employeeskills
  has_many :skills, :through => :employeeskills
  belongs_to :company
  has_many :contracts
end

class Skill < ActiveRecord::Base
  has_many :employeeskills
  has_many :employees, :through => :employeeskills
end

class Employeeskill < ActiveRecord::Base
  belongs_to :employee
  belongs_to :skill
end

class Contract < ActiveRecord::Base
  belongs_to :employee
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :contracts
end

Then you can ask for @user.contracts or @employee.skills etc.

Hope that helps!

情愿 2024-12-11 03:44:13

我不确定有什么开源项目值得一看,但您是否已阅读过Rails 入门指南?它涵盖了基本的关联。

I'm not sure of any open source projects to look at but have you been through the Getting Started Rails Guide? It covers basic associations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文