Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm and model inheritance
  • Hello! I'm working on my first project with fuelPHP and wanted to try using ORM but ran into this issue: I'm using a composite with a class "Subject" and two derived classes, "Group" and "Person", where each Group and each Person can be member of an arbitrary number of groups. In my database, so far I have three tables: subjects, groups and persons (plus groups_subjects) with 1:1 relations between subjects and groups resp. persons as well as a n:m relation between groups and subjects (indicating membership). So my question is, how to make ORM work with this? ps: in case it matters, I'm using 1.1
  • Ok, thank you for your estimation.
    That means, for this time I will start my model from scratch.
  • Yes, I've read that but couldn't figure out how to implement inheritance between models.
    Could you help me out? If I have something like this:
    class Subject extends Orm\Model
    {
       $_tablename = 'subjects';
       $_properties = array('id', 'name');
    }
    class Person extends Subject
    {
       $_tablename = 'persons';
       $_properties = array('id', 'password');
    }
    
    how do I continue?
  • But why do you want inheritance between models? The whole point of relations is to make composits of objects instead of inheriting. And I'm not sure what this has to do with relations as inheritance has nothing to do with establishing relations.
  • I'm using inheritance because I wanted to use the composite pattern, treating all subjects polymorphically.
    And to database relations this is insofar related, as I'm using class table inheritance to map the inheritance structure to database. I'm sorry, if my first post wasn't clear about this.
  • Hmm, it may be doable but you'll have to dive into the ORM\Model code and perform some trickery to get this right. This would be doable with a DataMapper implementation but with the way in which we implemented this ActiveRecord it's not really meant to be used in this way. (we will be moving to a DM implementation in Fuel 2, but that won't be released anytime soon)

Howdy, Stranger!

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

In this Discussion