Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]Maglok[/eluser]
I dug in the datamapper code and went and did some var_dumps of what exactly he is trying to make a relationship of. I put the working and not working ones besides each other and they are exactly the same. I am confused.

Code:
// model Skill
  'class' =>
    array (size=8)
      'class' => string 'ccclass' (length=7)
      'join_self_as' => string 'skill' (length=5)
      'join_other_as' => string 'class' (length=5)
      'join_table' => string 'ccj_ru_class_skill' (length=18)
      'other_field' => string 'skill' (length=5)
      'reciprocal' => boolean false
      'auto_populate' => null
      'cascade_delete' => boolean true
  'class_skills' =>
    array (size=8)
      'class' => string 'ccclass' (length=7)
      'join_self_as' => string 'skill' (length=5)
      'join_other_as' => string 'ccclass' (length=7)
      'join_table' => string 'ccj_ru_class_skill' (length=18)
      'other_field' => string 'skill' (length=5)
      'reciprocal' => boolean false
      'auto_populate' => null
      'cascade_delete' => boolean true

Code:
// model CCClass
  'skill' =>
    array (size=8)
      'class' => string 'skill' (length=5)
      'join_self_as' => string 'class' (length=5)
      'join_other_as' => string 'skill' (length=5)
      'join_table' => string 'ccj_ru_class_skill' (length=18)
      'other_field' => string 'ccclass' (length=7)
      'reciprocal' => boolean false
      'auto_populate' => null
      'cascade_delete' => boolean true
  'class_skills' =>
    array (size=8)
      'class' => string 'skill' (length=5)
      'join_self_as' => string 'class' (length=5)
      'join_other_as' => string 'skill' (length=5)
      'join_table' => string 'ccj_ru_class_skill' (length=18)
      'other_field' => string 'ccclass' (length=7)
      'reciprocal' => boolean false
      'auto_populate' => null
      'cascade_delete' => boolean true

[eluser]WanWizard[/eluser]
In your first post they are definately not the same.

- class: the name of the model class on the other side of the relation (to load the other model class)
- other_field: the name of the relation on the other side of the relation (for reverse relation lookup)
- join_self_as: the name of the column that identifies THIS model in the relation, suffixed by '_id'
- join_other_as: the name of the column that identifies THE OTHER model in the relation, suffixed by '_id'

So your first non-working example should be
Code:
// model Skill
   'class_skills' => array(
     'class' => 'ccclass',
     'other_field' => 'class_skills',
     'join_self_as' => 'skill',
     'join_other_as' => 'ccclass',
     'join_table' => 'ccj_ru_class_skill')

// model CCClass
   'class_skills' => array(
     'class' => 'skill',
     'other_field' => 'class_skills',
     'join_self_as' => 'ccclass',
     'join_other_as' => 'skill',
     'join_table' => 'ccj_ru_class_skill')

This requires your join table to contain the columns ccclass_id and skill_id.

If other_field is not correct, the relation reverse lookup doesn't work, hence the message that the relation could not be found.

[eluser]Maglok[/eluser]
Aha!

I see it now. Donders, shoulda seen that.

Ok so here is what my mind did: 'other_field' = 'something in the database', but it is the name of the relationship, aka the key of the array, aka 'class_skills'

That is it. Smile

Have I finally unraveled the final bits of advanced relationships? Will I be able to think up any relationship possible? Tune in next time. Smile

[eluser]WanWizard[/eluser]
lol.

I have to agree it's not very logically named. It's legacy from a distant past...

[eluser]Maglok[/eluser]
But an awesome legacy. Trust me we got some sites and scripts that were way before my time here that are from like 2004. Datamapper is futuretech compared to that. Smile

[eluser]WanWizard[/eluser]
I can beat that, my first PHP app, which is still running, dates back to 1999.

Had to go through several hack rounds to make it run on 5.3 though.... Wink

[eluser]Maglok[/eluser]
Amen. I am beaten.

Here's another theoretical. (Now I am thinking through some scenarios and wondering how to do them with datamapper).

How would you model this: http://martinfowler.com/eaaCatalog/class...tance.html in datamapper? Mainly that in that example Cricketer would inherit 'name' from Player. I assume that the cricketer table would have a player_id to reference back.

Just a theoretical this time, don't have a use for it (yet).

PS: I take back the mention of the extreme heat, today it is rain rain rain.

[eluser]WanWizard[/eluser]
Most of Fowler's book doesn't apply, because contrary to what the name would suggest, Datamapper implements the Activerecord pattern, not the Datamapper pattern (blame my predecessors Wink).

In an Activerecord pattern there's a one-on-one mapping between the object and it's table row, and both code and data is a single object. This makes it very complex to create data structures that aren't a one-on-one mapping to a table, so inheritance and polymorphism are "very difficult" to implement.

Another point is most people use the ORM the wrong way. If you read up on it, you'll notice that outside code should interact with model methods, and model methods interact with the datastore.

That means you should not use this in your controllers:
Code:
$user->where('group', 'admins')->where('status', 'active')->get();
but
Code:
$user->get_active_admins();

The last option allows you to hide complex code from your controllers. You get an object back, you don't know from where the data came. Could have been a webservice instead of a table. Or from different tables (in your theoretical case).

Unfortunately most ORM's provide strong query builder features, stronger than the native framework solution, so people tend to use the ORM as a glorified query builder. Most never get any further with their models then added a table name, relations, and sometimes some validation.

With the Datamapper pattern you have separate data and code objects. Often a Datamapper based ORM doesn't include a query builder, but relies on an external DBAL, which forces you to either use DBAL calls in your code (think $this->db) or ORM method calls. But you can't use DBAL calls through ORM objects.

It's one of the biggest issues I'm struggling with for the design of 2.0. Ideally I would like this separation, but it would mean breaking with the past, and an upgrade nightmare. 2.0 no longer uses the frameworks QB (no more $this->db in the case of CI), but will come with it's own DBAL (I'm going to use http://github.com/FrenkyNet/Cabinet), if only because I no longer want to be dependent on the CI dev's making changes to the libraries that require hacks to make DM work again.

I'm currently trying to work my way out of this dilemma, by seeing if it's possible to use a 'legacy' extension with would re-introduce DBAL access through the ORM for migration purposes. But I haven't made up my mind yet.

[eluser]Maglok[/eluser]
Hmm that is one sneaky way of naming the library. Is like "Here is a Apple" and then you get an Orange Wink

I am a firm believer of thin controller fat model. I got this one application that has a huge datamapper model class that juggles 9 other ones, that juggle even more. All I do in controller is get_character($name). I have to admit I tend to cut some corners when I am in a rush or testing some things.

I can see your dilemma then. With server tech like this I do believe it is sometimes ok to simply drop legacy support. CI dropped PHP4 code at some point afterall and if it is neccesary then it is.

There is no way to somehow introduce a 'driver' concept like with CI itself. Use either CI core or Cabinet database abstraction layer like how you could swap between mysql and mssql. I can see that being an extremely big nightmare though. Tongue

[eluser]willaser[/eluser]
[quote author="WanWizard" date="1346222161"]I don't think the spark contains the latest fixes. I tried to update it, but getsparks doesn't understand the 1.8.2.1 version (they only work with 3 digits).

Get the zip from bitbucket instead, and install the latest version manually.[/quote]

I have tried what you said: I copied all the bitbucket files and I adapted the APPPATH to DATAMAPPERPATH but I end at the same point.

Any advise?




Theme © iAndrew 2016 - Forum software by © MyBB