partitioning / inherit models
Christoph Os...
9 posts
|
Hi, i want to explain what i want to do with the following example: I want to model students and employees. With EER i would use partitioning to do that and create a model persons, to carry the attributes both, students and emploees, have in common.
Now i had to pass the attributes out of params[:xy] in view/students/new to a call of Person.new() ...quite verbous, and since i remember i had problems to validate the fields that belong to Person. Maybe i should do something like the following:
Sad wise there are no examples for inheritance among models in the book. Hope somehone has suggestions. |
James West
73 posts
|
I’m not entirely sure that would work. In another environment I would have an abstract base class of person and the employee and studemt classes would inherit from this. I think that doing things that way is do-able but not ideal and would need you to re-think the database design somewhat. i.e. having a person type that can be set to either employee or student in the specific relevant model class. I hope this makes sense and I stand to be corrected. Is there another way? There will undoubtedly be another way that will enable you to closer mapyour database in this way but I really don’t know what that way would be and for me to suggest anything would be a case of the blind leading the blind. It might be worth taking a look at helpers as an option for views and it may be that you could have a module that you could mix in with your controllers in order to share code wthout the need to inherit. I only got that idea coz I’ve just been reading page 686 about modules and it seems like it fits |
Christoph Os...
9 posts
|
mea culpa, mea maxima culpa… for those who were as sleepy as me, while reading 18.4. There is the answer. |
3 posts, 2 voices
