Re: how should I set up these complex associations?

2007-04-18 Thread Mike Griffin

On 4/13/07, gerbenzomp <[EMAIL PROTECTED]> wrote:
> I think there's something wrong with my associations in general,
> because I get an array that looks different from what I had hoped for,
> and the error stays too. (It goes away when I remove the page->widget
> association, which is in a way understandable, because a page contains
> no widgets: a page contains layers, which in turn contain widgets.

I think you don't need a relationship between the page and widget then
in that case.
Page hasMany Layer
Layer hasMany Widget

Is this more like what you are looking for?

If you think more in those terms, it will be easier for you to figure
out how to lay out your design.  I dont really understand what you are
trying to do with it all though.

Mike.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how should I set up these complex associations?

2007-04-15 Thread gerbenzomp

I've been thinking about this problem some more, and maybe I need
HABTM-associations between the pages and widgets, as well as between
the layers and the widgets? Or would that make it unneccesarily
complex?

I want to generate an array based on the current page, and then print
the layers, and the widgets each layer contains, so maybe there's a
much simpler approach. It's just that I can't see how to do this.


On 13 apr, 16:18, "gerbenzomp" <[EMAIL PROTECTED]> wrote:
> You mean in the model? I've tried that before, but it doesn't change
> the error.
>
> I think there's something wrong with my associations in general,
> because I get an array that looks different from what I had hoped for,
> and the error stays too. (It goes away when I remove the page->widget
> association, which is in a way understandable, because a page contains
> no widgets: a page contains layers, which in turn contain widgets.
>
> It's hard for me to have a clear understanding of how I should set
> this up.
>
> On 13 apr, 13:38, "Mike Griffin" <[EMAIL PROTECTED]> wrote:
>
> > On 4/13/07, gerbenzomp <[EMAIL PROTECTED]> wrote:
>
> > > But I think this isn't the right approach, because I get the error:
> > > SQL Error in model Page: 1052: Column 'id' in order clause is
> > > ambiguous
>
> > You need to use the model name in front of the id as well.
> > Something like Page.id or Widget.id, depending on which one you want.
>
> > Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [EMAIL PROTECTED]
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
-~--~~~~--~~--~--~---



Re: how should I set up these complex associations?

2007-04-13 Thread gerbenzomp

You mean in the model? I've tried that before, but it doesn't change
the error.

I think there's something wrong with my associations in general,
because I get an array that looks different from what I had hoped for,
and the error stays too. (It goes away when I remove the page->widget
association, which is in a way understandable, because a page contains
no widgets: a page contains layers, which in turn contain widgets.

It's hard for me to have a clear understanding of how I should set
this up.

On 13 apr, 13:38, "Mike Griffin" <[EMAIL PROTECTED]> wrote:
> On 4/13/07, gerbenzomp <[EMAIL PROTECTED]> wrote:
>
> > But I think this isn't the right approach, because I get the error:
> > SQL Error in model Page: 1052: Column 'id' in order clause is
> > ambiguous
>
> You need to use the model name in front of the id as well.
> Something like Page.id or Widget.id, depending on which one you want.
>
> Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [EMAIL PROTECTED]
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
-~--~~~~--~~--~--~---



Re: how should I set up these complex associations?

2007-04-13 Thread Mike Griffin

On 4/13/07, gerbenzomp <[EMAIL PROTECTED]> wrote:
> But I think this isn't the right approach, because I get the error:
> SQL Error in model Page: 1052: Column 'id' in order clause is
> ambiguous

You need to use the model name in front of the id as well.
Something like Page.id or Widget.id, depending on which one you want.

Mike.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [EMAIL PROTECTED]
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
-~--~~~~--~~--~--~---



Re: how should I set up these complex associations?

2007-04-13 Thread gerbenzomp

I'll try to be a bit more specific: my main problem is that a Widget
belongs only to the combination of layer and page, and is linked
through layer_id and page_id. A page in turn only has an association
with a layer through the design model.

Right now I have this:

class Page extends AppModel
{
var $name = 'Page';

var $belongsTo = array('Design' =>
 array('className' => 'Design',
   'conditions'=> 
'',
   'order' => '',
   'foreignKey'=> 'design_id'

 )
);


var $hasMany = array('Widget' =>
 array('className' => 'Widget',
   'conditions'=> 
'',
   'order' => 'Page.url',
   'foreignKey'=> 'page_id'

 )
);

}

class Layer extends AppModel
{
var $name = 'Layer';

// a layer holds many widgets
var $hasMany = array('Widget' =>
 array('className' => 'Widget',
   'conditions'=> 
'',
   'order' => 'Widget.order_id
DESC',
   'limit' => '',
   'foreignKey'=> 'layer_id',
   'dependent' => true,
   'exclusive' => false,
   'finderQuery'   => ''
 )
);
// a layer belongs to a design
var $belongsTo = array('Design' =>
 array('className' => 'Design',
   'conditions'=> '',
   'order' => 'Design.id DESC',
   'limit' => '',
   'foreignKey'=> 'design_id',
   'dependent' => true,
   'exclusive' => false,
   'finderQuery'   => ''
 )

);

}

But I think this isn't the right approach, because I get the error:
SQL Error in model Page: 1052: Column 'id' in order clause is
ambiguous

The error only goes away when I remove the association between Page-
>Widget

I could also do a custom query:
query("SELECT * from widgets_table WHERE page_id = $page_id AND
layer_id = $layer_id);

but I think that would be a hack. I just don't know how to set up the
associations.

Any help is appreciated!


On 13 apr, 00:03, "gerbenzomp" <[EMAIL PROTECTED]> wrote:
> I've been trying to get the associations right, but I somehow got lost
> in my thinking about how every model relates to the other. Maybe
> someone can have a fresh view on my problem.
>
> I've put all my models between "" in this explanation, so it is easier
> to read.
>
> I have several models:
>
> All the "Pages" in a "Site" share the same "Design"
> Each "Design" has many "Layers", and each "Layer" can have many
> "Widgets", BUT the widgets in each layer are also dependant of the
> current "Page".
>
> Every "Page" in a site uses the same "Design" and thus the same
> "Layers", but the widgets in the layers can vary from page to page.
>
> I hope I'm being clear in my description above.
>
> I was able to set up the relations to a good degree, but got stuck
> when I realised that widgets don't belong to a layer, but ONLY to the
> combination of "Page" and "Layer". And layers belong to a design, but
> widgets DON'T belong to a design.
>
> Any ideas how this would translate to Cake associations?
>
> Any help in my thinking about this would be appreciated as well :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [EMAIL PROTECTED]
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
-~--~~~~--~~--~--~---