hesedwebdev Posted August 6, 2013 Share Posted August 6, 2013 Hello, I am working through the tutorial for Yii on the website, and I have setup the Employee and Department models. However, this only addresses if an Employee has 1 department. What would I need to do if I wanted to be able to list multiple departments under the column 'departmentId' separated by commas or pipes, etc? Link to comment Share on other sites More sharing options...
hesedwebdev Posted August 6, 2013 Author Share Posted August 6, 2013 I guess I should shed more light. I know I would need something in the models to take the field under departmentId and evaluate if it has the chosen separator (for sake of the example, I will say the separator is ',' [*comma*]) and then break that into an array. Then the relations should run through the array and get all the departments that match those IDs. But since I am obviously new to Yii, I do not know if: A. How or what needs to be edited, OR B. If there is an easier or better way to do this. I have thought about making an employeesDepts table that has individual entries of every departmentId for an employeeId, but then again incorporating this is my difficulty. Any help is greatly appreciated. Link to comment Share on other sites More sharing options...
Antonio Conte Posted August 6, 2013 Share Posted August 6, 2013 Your last thought is the right one. This is a one-to-many relationship that needs an table like employeesDeptartments. Larry writes about this in the sub-chapter starting at page 109. (Or thereabout - Larry has released lots of versions so far.) Link to comment Share on other sites More sharing options...
hesedwebdev Posted August 6, 2013 Author Share Posted August 6, 2013 Thank you Antonio. I am glad my last thought was correct, and conceptually I have it, but I am just at the point now of how to make it all work. Link to comment Share on other sites More sharing options...
Recommended Posts