RE: CakePHP for Railers

2006-10-26 Thread Jörg W Mittag

Felix Geisendörfer wrote:
> One of the things that I really like as well is creating 
> Models for relationships. I think I heard about it first in 
> David Heinemeier Hansson Keynote Adress at RailsConf '06 
> (Video 
>
 ,
> Slides 
).

Busted!  That's where I stole the Membership example from (-;

> I've played around with it a while back in CakePHP and got 
> it working without using a through relationship. Maybe I've 
> missed something, but I'll try to reproduce it today an write 
> a post about it on ThinkingPHP.org  .

Very nice writeup, thank you.

jwm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: CakePHP for Railers

2006-10-25 Thread Felix Geisendörfer




Jörg,

thanks for your lengthy post, it was a pretty interesting read.

One of the things that I really like as well is creating Models for
relationships. I think I heard about it first in David Heinemeier
Hansson Keynote Adress at RailsConf '06 (Video,
Slides).
I've played around with it a while back in CakePHP and got it working
without using a through relationship. Maybe I've missed something, but
I'll try to reproduce it today an write a post about it on ThinkingPHP.org.

Other then that, this polymorphic association stuff sounds very
interesting as well, but I can't see a reason why this is something
only Ruby can do.

A little o.T.: for those of you who are really into OOP and would like
results of Model queries to be objects as well and similar things:
Afaik CakePHP relies heavily on Arrays for a lot of things because they
are a far superior choice in PHP 4 & 5 over objects. Sure PHP is an
object oriented language, but have you seen a lot of functions to
manipulate objects? I haven't. PHP is really all about manipulating
arrays. Whenever I have to work with another language I instantly miss
PHP's sweet array functions. This said, it's also clear why PHP 5 isn't
dominant yet, it simply didn't deliver anything outstanding that PHP 4
didn't already have (name spaces would have been cool). I myself am
quite happy using PHP 4 and would only switch if CakePHP goes that way
(in 2.0) or my hosting company does.

Best Regards,
Felix Geisendörfer
--

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---





Re: CakePHP for Railers

2006-10-25 Thread Chris Hartjes

On 10/25/06, Jörg W Mittag <[EMAIL PROTECTED]> wrote:
>
> >>  - object-relational mapping of inheritance
> > I think CakePHP allows this through object chaining, which to
> > me is a very powerful yet underutilized concept.
>
> Can you elaborate on that?  I just googled for object chaining
> and only got a few results concerning fluent interfaces which is
> probably not what you meant.
>

By object chaining, I mean you can do something like this:

$foo = $this->foo->bar->baz->findAll();

It requires that your class methods return objects instead of arrays.
Rails does it as well, so maybe I'm calling it by the wrong name.
It's a design decision when you build you objects, for sure.  Me, I'm
a "let's return everything as associative arrays" type of guy.


-- 
Chris Hartjes

"The greatest inefficiencies come from solving problems you will never have."
-- Rasmus Lerdorf

@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: CakePHP for Railers

2006-10-25 Thread Jörg W Mittag

nate wrote:
>>  - Acts (acts allow you to decorate a model's behaviour with
>>  additional orthogonal aspects and encapsulate that behaviour
>>  in a single, central place)
> We have something called 'Behaviors' in Cake 1.2.  There have 
> been a few posts on it in this mailling list which you can 
> search for, but thus far none have been released.

Very cool!

jwm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: CakePHP for Railers

2006-10-25 Thread Jörg W Mittag

Thanks Chris,

Chris Hartjes wrote:
>>  - join models
> CakePHP offers that via the same sort of hasMany, belongsTo 
> and hasManyAndBelongsTo functionality.

That seems to have been misunderstood.  I was thinking of using 
real join Models in the Domain Model for many-to-many 
relationships instead of "mere" join tables at the database level 
that have no representation whatsoever in the object-oriented 
layer.  So, instead of this:

CREATE TABLE `groups_users`
( `group_id` INTEGER UNSIGNED NOT NULLDEFAULT 0
, `user_id`  INTEGER UNSIGNED NOT NULLDEFAULT 0
, PRIMARY KEY `groups_users_id` (`groups_id`, `users_id`)
, FOREIGN KEY (`group_id`) REFERENCES `groups`(`id`)
, FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
);

with

User has and belongs to many Groups

Group has and belongs to many Users

You would instead have this:

CREATE TABLE `memberships`
( `id`   INTEGER UNSIGNED PRIMARY KEY auto_increment
, `group_id` INTEGER UNSIGNED NOT NULLDEFAULT 0
, `user_id`  INTEGER UNSIGNED NOT NULLDEFAULT 0
, FOREIGN KEY (`group_id`) REFERENCES `groups`(`id`)
, FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
);

with

Membership belongs to User
Membership belongs to Group

User has many Memberhips
User has many Groups through Memberships

Group has many Memberships
Group has many Users through Memberships

Basically, our poor little anymous join table has been promoted 
to a real Membership Model in our application.

Using a real full-fledged join model gives you much more power 
and flexibility.  Consider, for example, trying to design a 
RESTful CRUDdy API for this application.  In the first example 
above, it is not immediately obvious how to join a User to a 
Group.  Of course, it's possible to add a joinGroup action to 
your User model or an acceptUser action to your Group model.  But 
that wouldn't be RESTful and CRUDdy.  In the second example, it's 
blindingly obvious: joining a Group is the same as creating a new 
Membership.

Modeling relationships between models as models in their own 
right is a very powerful concept.  Unfortunately, many courses 
still teach this naive noun/verb modeling concept, where you 
basically write up your use cases in plain English and then 
underline all nouns which become your objects and all verbs which 
become your actions.  In this way you usually overlook concepts 
such as Relationship, Authorship, Membership etc., which might 
very well deserve their own objects, instead of being just 
associations.

>>  - object-relational mapping of inheritance
> I think CakePHP allows this through object chaining, which to 
> me is a very powerful yet underutilized concept.

Can you elaborate on that?  I just googled for object chaining 
and only got a few results concerning fluent interfaces which is 
probably not what you meant.

AFAICS, there are basically 6 possibilities how to do 
object-relational mapping of inheritance:

 1. cop-out #1: don't do inheritance
 2. cop-out #2: don't do object-relational mapping, use a "real" 
  object-oriented database/persistence layer instead
 3. map the complete inheritance hierarchy to a single table 
  (a.k.a. the "One Inheritance Tree - One Table", "Single 
  Table Mapping", "Flat Mapping", "Union Mapping", "Typed 
  Mapping", "Filtered Mapping" or "Single Table Inheritance" 
  design pattern)
 4. map each concrete class to a single table (a.k.a. the "One 
  Inheritance Path - One Table", "Horizontal Mapping" or 
  "Concrete Table Inheritance" design pattern)
 5. map each class to a single table (a.k.a the "One Class - 
  One Table", "Vertical Mapping" or "Class Table Inheritance" 
  design pattern)
 6. use a generic "meta-mapping" schema

All of these have their advantages and disadvantages.

#3 is probably the simplest of those (except #1, of course), it 
works like this: in your database you have one single table for 
the entire inheritance hierarchy which includes the union of all 
attributes of the classes in the hierarchy plus an additional 
type column.  So, given a hierarchy like this:

class Article {
var $title;
var $body;
}

class BlogPost extends Article {
var $category;
}

class Comment extends Article {
var $blogpost;
}

your schema would look like this:

CREATE TABLE `articles`
( `id`  INTEGER UNSIGNED PRIMARY KEY
auto_increment
, `title`   VARCHAR(255) NOT NULL
, `body`TEXT NOT NULL
, `blog_post_category`  VARCHAR(255) NULL
, `comment_blog_post_id`INTEGER UNSIGNED NULL
, `type`VARCHAR(255) NOT NULL
, FOREIGN KEY (`com

Re: CakePHP for Railers

2006-10-25 Thread nate

https://trac.cakephp.org/browser/branches/1.2.x.x/cake/libs/model/behavior.php

Just because we haven't released any doesn't mean you can't write one
yourself :-P


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Re: CakePHP for Railers

2006-10-25 Thread Samuel DeVore

tease

On 10/25/06, nate <[EMAIL PROTECTED]> wrote:
>
> >  - Acts (acts allow you to decorate a model's behaviour with
> >  additional orthogonal aspects and encapsulate that behaviour
> >  in a single, central place)
>
> We have something called 'Behaviors' in Cake 1.2.  There have been a
> few posts on it in this mailling list which you can search for, but
> thus far none have been released.
>
>
> >
>


-- 
==
S. DeVore
(the old fart) the advice is free, the lack of crankiness will cost you

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: CakePHP for Railers

2006-10-25 Thread nate

>  - Acts (acts allow you to decorate a model's behaviour with
>  additional orthogonal aspects and encapsulate that behaviour
>  in a single, central place)

We have something called 'Behaviors' in Cake 1.2.  There have been a
few posts on it in this mailling list which you can search for, but
thus far none have been released.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: CakePHP for Railers

2006-10-25 Thread Chris Hartjes

Hey there jwm,

I've got experience with both Rails and CakePHP.  In fact, I even gave
a talk at the php|works conference in September on the topic of "What
Can PHP Learn From Ruby On Rails?", so I'd like to think I'm qualified
to comment on this topic.  I'm sure I'll be corrected if I'm wrong.
I've made my comments inline below:


>
>  - join models

CakePHP offers that via the same sort of hasMany, belongsTo and
hasManyAndBelongsTo functionality.  CakePHP very much supports the
"convention over configuration" concept for databases

>  - object-relational mapping of inheritance

I think CakePHP allows this through object chaining, which to me is a
very powerful yet underutilized concept.

>  - polymorphic associations

PHP doesn't support the polymorphic stuff at this time as far as I'm aware.

>  - Acts (acts allow you to decorate a model's behaviour with
>  additional orthogonal aspects and encapsulate that behaviour
>  in a single, central place)

Nope...but I believe that is due to the fact that PHP does not support
closures, a key feature that makes all sorts of awesome feature
available in Rails.

>  - join models

Not sure.

>  - the migration DSL (in fact, all of Rails' DSLs, including but
>  not limitied to the Model DSL)

There's no migrations...but that would be an interesting project.
Maybe I should look into this as it would be something very
interesting.

Hope that helps.

-- 
Chris Hartjes

"The greatest inefficiencies come from solving problems you will never have."
-- Rasmus Lerdorf

@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---