Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
subclasses within ORM\Models
  • This may be a silly or noobish question (I have much deeper to go in my mastery of OOP) and if so, apologies! I have a Model_User, mapped to the users table in my db. However, my application has three types of users - artists, voters and volunteers. Some of the fields in the users table apply to all three and some only apply to one. What I'd like to do is extend my Model_User with subclasses for each user type - Model_Artist, Model_Voter, Model_Volunteer. Each of the user subclasses would have $_properties from the users table that pertain only to that type. The Model_User would have $_properties that pertain to all three. My question is basically is this ok with Fuel's ORM? Will this work or will it completely break the db mapping? If the latter, how can I best implement this sort of division between my various user types? Thanks very much for any help!
  • It shouldn't be a problem, but in this case I wouldn't recommend inheritance as the solution. Composition is probably better here: have the basic information as the Model_User and create HasOne relations to Model_Artist/Voter/Volunteer that provide the additional information depending on which type it is.
  • Thanks Jelmer!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion