Re: Creating Dynamic Model Associations

2007-01-18 Thread anselm



I know you can, on the fly, do new associations (or is this v1.2?)


You can in 1.1 too -- see bindModel/unbindModel in the 'model' chapter
of the manual (also often refered to in this group)


but
they only work for the next query.  Is this correct?


Well - yes ;)

But it shouldn't be difficult to have them created automatically ? How
about : In your AppModel class, add a constructor (__construct -- Cake
makes it work in php4 too) which checks for a inherits variable, and
then registers your association accordingly.

class Article extends AppModel
{
 var $inherits = 'Item';
}

Internally, Cake only keeps one copy of each Model -- so $item =
ClassRegistry::getObject('Item') should return the the Item model that
is used everywhere ; you can easilly call bindModel on this object, and
the association will be valid everywhere.

Anselm


--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Creating Dynamic Model Associations

2007-01-17 Thread Dave Rogers

In my latest project, I am trying to make particular Models/Controllers
inherit from other Models/Controllers that I create.  For example:

Items
 -- Article
  -- News
  -- Event

In particular, I am trying to figure out the model association, so that
I can plug in a new Model and Controller and it all works magically.

My current Items Model is:

?php
class Item extends AppModel {
var $name = 'Item';

var $hasMany = array(
'Event' =
array('className' = 'Event',
'conditions'= '',
'order' = '',
'limit' = '',
'foreignKey'= 'item_id',
'dependent' = true,
'exclusive' = false,
'finderQuery'   = ''
)
);
}
?

I don't want to have to go in and edit the Items model every time I get
a new model that inherits from Item.

I know you can, on the fly, do new associations (or is this v1.2?) but
they only work for the next query.  Is this correct?

Thanks for your help.


--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---