Note that there are some explanatory texts on larger screens.

plurals
  1. PORails - data view from has_many and Has_many_and_belongs_to_many
    primarykey
    data
    text
    <p>I'm trying to implement this project: </p> <p><a href="http://img7.imagebanana.com/img/cnb46ti2/relationships.png" rel="nofollow">http://img7.imagebanana.com/img/cnb46ti2/relationships.png</a></p> <ul> <li>I want to let view the skills of an employee on the employee's show page </li> <li>An employee has a position, and every position has skills which an employee of this position needs to know </li> <li>so if I understand right, positions and skills have an n:m relationship, and they need a join table for a has_many_and_belongs_to_many relationship. Because a position includes many skills and every skill belongs to many positions. </li> </ul> <p>now my questions </p> <ol> <li>the position_skill-table -> is it better to use a has_and_belongs_to_many relationship, so this table has no own id or is it better to use a has_many :through relationship? I guess it's better do use a has_and_belongs_to_many relationship, because this relationship table will not have any further information inside than just the two keys. Am I right?</li> <li>if I take a has_and_belongs_to_many - relationship, is that the only thing I need to write into the models? </li> </ol> <p>a) <code>class Position &lt; ActiveRecord :: Base (...) has_and_belongs_to_many :skills (...)</code> </p> <p>b) <code>class Skill &lt; ActiveRecord :: Base (...) has_and_belongs_to_many :positions (...)</code></p> <p>c) into db\migrate <code>def self.up create_table :positon_skill, :id =&gt; false do |t| (...)</code> and after that, the positions and skills are connected with each other? Is that right? Did I forget something?</p> <ul> <li>if that's right, how can I let the skills view on employee's show page? An employee has 1 position, and this position has several skills... What for code do I need to write into the show.html.erb of employee? Something like <code>&lt;%= employee.position.skill %&gt;</code>? Do I also need to render something? Sorry, I'm very confused and I think I read too much information in web... Or is there any description in web which exactly describes what I need for?</li> </ul> <p>thanks alot in advance and sorry for that redundant question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload