Re: How to prevent circular relationships ?

2009-07-09 Thread Brendon Kozlowski (Realm)

I believe gwoo has created a Workbench -> Cake model script
somewhere...IIRC the code for it is in the CakeBin.
http://bin.cakephp.org/saved/45105

Found from:
http://groups.google.com/group/cake-php/browse_thread/thread/a94d882f105753dc?hide_quotes=no

On Jul 8, 8:57 pm, Mike Bates  wrote:
> I use it to build my schemas then go to File > Export > forward engineer SQL
> CREATE Script.
>
> That gives the full sql to build the database on mysql, and once cake is
> configured to see your db the bake script will pick up everything (as you
> probably already know)
>
> You can also export the ALTER scripts for existing databases.
>
> You do need to follow the cake naming convension, and you can edit the
> settings in workbench at Tools > Options > Model tab.
>
> I don't know of a way to get workbench to convert plural to singular though,
> but it's an easy edit so I haven't bothered to look into it too closely.
>
>
>
> On Wed, Jul 8, 2009 at 12:08 PM, Jon Chin  wrote:
> > Thanks for the tip.  I installed MySQL Workbench.  It looks like a sweet
> > program, but I'm not totally sure what it does for me.  I've imported my
> > current database tables and created a few EER diagrams.  Other than database
> > planning and documentation, what else can this tool do?  Is there a way to
> > export it to something Cake can interpret?  Please enlighten me.
>
> > Also, when I create a relationship between tables in the program, it
> > creates a new foreign key like this: tablename_id.  But Cake syntax is
> > singulartablename_id.  Do you know if there's a way to change that Workbench
> > default?
>
> > Jon Chin
>
> > Mike Bates wrote:
>
> >> Is there a reason for Machine and Service to have many to many
> >> relationships (machine with Type and category, Service with customer)? 
> >> There
> >> are often complications when you have db design with many to many
> >> relationships.
>
> >> Try creating new tables in between them so you can have HABTM between
> >> machine and type, machine and category, service and customer.
>
> >> When designing your schema this is a great free tool
>
> >>http://dev.mysql.com/downloads/workbench/5.1.html
>
> >> It'll create an EER diagram for you, and using that as a visual aid helps
> >> a lot when putting your schema together.
>
> >> On Wed, Jul 8, 2009 at 8:08 AM, iFeghali  >> igor.fegh...@gmail.com>> wrote:
>
> >>    Hello All,
>
> >>    I am stuck at a circular relationship problem. This is my scenario:
>
> >>    - Machine HABTM Service HABTM Machine
> >>    - Machine belongsTo Type hasMany Machine
> >>    - Machine belongsTo Category hasMany Machine
> >>    - Service belongsTo Customer hasMany Service
>
> >>    So far so good. When the user goes to /machine/view it expects to see:
>
> >>    [level 0] machine
> >>    [level 1] machine type
> >>    [level 1] machine category
> >>    [level 1] services
> >>    [level 2] services customers
>
> >>    If I set recursive to 1, the last item will not be retrieved. If i set
> >>    recursive to 2, everything goes well except I get machine records for
> >>    type, category and services (too much unwanted data).
>
> >>    I could let recursive = 2 and manually unbind machine from all other
> >>    models in the view action, but that would be too much extra code for
> >>    something apparently simple. note that the given scenario is just an
> >>    exemplification, my real case has around 8 models tied on a complex
> >>    "web".
>
> >>    I could also made relationships one way only, but obviously it would
> >>    break the views for the other models.
>
> >>    so my question is whether i can set recursive to 2, but tells cake not
> >>    to retrieve the main model thus preventing "circular data".
>
> >>    Thank you.- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to prevent circular relationships ?

2009-07-08 Thread Mike Bates
I use it to build my schemas then go to File > Export > forward engineer SQL
CREATE Script.

That gives the full sql to build the database on mysql, and once cake is
configured to see your db the bake script will pick up everything (as you
probably already know)

You can also export the ALTER scripts for existing databases.

You do need to follow the cake naming convension, and you can edit the
settings in workbench at Tools > Options > Model tab.

I don't know of a way to get workbench to convert plural to singular though,
but it's an easy edit so I haven't bothered to look into it too closely.

On Wed, Jul 8, 2009 at 12:08 PM, Jon Chin  wrote:

> Thanks for the tip.  I installed MySQL Workbench.  It looks like a sweet
> program, but I'm not totally sure what it does for me.  I've imported my
> current database tables and created a few EER diagrams.  Other than database
> planning and documentation, what else can this tool do?  Is there a way to
> export it to something Cake can interpret?  Please enlighten me.
>
> Also, when I create a relationship between tables in the program, it
> creates a new foreign key like this: tablename_id.  But Cake syntax is
> singulartablename_id.  Do you know if there's a way to change that Workbench
> default?
>
> Jon Chin
>
>
>
>
> Mike Bates wrote:
>
>> Is there a reason for Machine and Service to have many to many
>> relationships (machine with Type and category, Service with customer)? There
>> are often complications when you have db design with many to many
>> relationships.
>>
>> Try creating new tables in between them so you can have HABTM between
>> machine and type, machine and category, service and customer.
>>
>> When designing your schema this is a great free tool
>>
>> http://dev.mysql.com/downloads/workbench/5.1.html
>>
>> It'll create an EER diagram for you, and using that as a visual aid helps
>> a lot when putting your schema together.
>>
>>
>> On Wed, Jul 8, 2009 at 8:08 AM, iFeghali > igor.fegh...@gmail.com>> wrote:
>>
>>
>>Hello All,
>>
>>I am stuck at a circular relationship problem. This is my scenario:
>>
>>- Machine HABTM Service HABTM Machine
>>- Machine belongsTo Type hasMany Machine
>>- Machine belongsTo Category hasMany Machine
>>- Service belongsTo Customer hasMany Service
>>
>>So far so good. When the user goes to /machine/view it expects to see:
>>
>>[level 0] machine
>>[level 1] machine type
>>[level 1] machine category
>>[level 1] services
>>[level 2] services customers
>>
>>If I set recursive to 1, the last item will not be retrieved. If i set
>>recursive to 2, everything goes well except I get machine records for
>>type, category and services (too much unwanted data).
>>
>>I could let recursive = 2 and manually unbind machine from all other
>>models in the view action, but that would be too much extra code for
>>something apparently simple. note that the given scenario is just an
>>exemplification, my real case has around 8 models tied on a complex
>>"web".
>>
>>I could also made relationships one way only, but obviously it would
>>break the views for the other models.
>>
>>so my question is whether i can set recursive to 2, but tells cake not
>>to retrieve the main model thus preventing "circular data".
>>
>>Thank you.
>>
>>
>>
>> >>
>>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to prevent circular relationships ?

2009-07-08 Thread Jon Chin
Thanks for the tip.  I installed MySQL Workbench.  It looks like a sweet 
program, but I'm not totally sure what it does for me.  I've imported my 
current database tables and created a few EER diagrams.  Other than 
database planning and documentation, what else can this tool do?  Is 
there a way to export it to something Cake can interpret?  Please 
enlighten me.


Also, when I create a relationship between tables in the program, it 
creates a new foreign key like this: tablename_id.  But Cake syntax is 
singulartablename_id.  Do you know if there's a way to change that 
Workbench default?


Jon Chin




Mike Bates wrote:
Is there a reason for Machine and Service to have many to many 
relationships (machine with Type and category, Service with customer)? 
There are often complications when you have db design with many to 
many relationships.


Try creating new tables in between them so you can have HABTM between 
machine and type, machine and category, service and customer.


When designing your schema this is a great free tool

http://dev.mysql.com/downloads/workbench/5.1.html

It'll create an EER diagram for you, and using that as a visual aid 
helps a lot when putting your schema together.



On Wed, Jul 8, 2009 at 8:08 AM, iFeghali > wrote:



Hello All,

I am stuck at a circular relationship problem. This is my scenario:

- Machine HABTM Service HABTM Machine
- Machine belongsTo Type hasMany Machine
- Machine belongsTo Category hasMany Machine
- Service belongsTo Customer hasMany Service

So far so good. When the user goes to /machine/view it expects to see:

[level 0] machine
[level 1] machine type
[level 1] machine category
[level 1] services
[level 2] services customers

If I set recursive to 1, the last item will not be retrieved. If i set
recursive to 2, everything goes well except I get machine records for
type, category and services (too much unwanted data).

I could let recursive = 2 and manually unbind machine from all other
models in the view action, but that would be too much extra code for
something apparently simple. note that the given scenario is just an
exemplification, my real case has around 8 models tied on a complex
"web".

I could also made relationships one way only, but obviously it would
break the views for the other models.

so my question is whether i can set recursive to 2, but tells cake not
to retrieve the main model thus preventing "circular data".

Thank you.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 
Groups "CakePHP" group.

To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

-~--~~~~--~~--~--~---



smime.p7s
Description: S/MIME Cryptographic Signature


Re: How to prevent circular relationships ?

2009-07-08 Thread Mike Bates
My fault, I wasn't reading your description correctly.

On Wed, Jul 8, 2009 at 9:53 AM, iFeghali  wrote:

>
> On Jul 8, 1:35 pm, Mike Bates  wrote:
> > Is there a reason for Machine and Service to have many to many
> relationships
> > (machine with Type and category, Service with customer)? There are often
>
> perhaps I misunderstand you but those relationships are defined as
> "one to many". e.g. a machine has only one type, but a type has lots
> of machines.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to prevent circular relationships ?

2009-07-08 Thread iFeghali

On Jul 8, 1:35 pm, Mike Bates  wrote:
> Is there a reason for Machine and Service to have many to many relationships
> (machine with Type and category, Service with customer)? There are often

perhaps I misunderstand you but those relationships are defined as
"one to many". e.g. a machine has only one type, but a type has lots
of machines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to prevent circular relationships ?

2009-07-08 Thread iFeghali

"Without Containable, you'd end up needing to use the unbindModel()
method of the model, multiple times if you're paring off multiple
models. Containable creates a cleaner way to accomplish this same
task."

seems a good alternative for me :)

thank you

On Jul 8, 1:35 pm, brian  wrote:
> Have you tried using Containable? It's much usually easier to work
> with than relying on 'recursive'.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to prevent circular relationships ?

2009-07-08 Thread Mike Bates
Is there a reason for Machine and Service to have many to many relationships
(machine with Type and category, Service with customer)? There are often
complications when you have db design with many to many relationships.
Try creating new tables in between them so you can have HABTM between
machine and type, machine and category, service and customer.

When designing your schema this is a great free tool

http://dev.mysql.com/downloads/workbench/5.1.html

It'll create an EER diagram for you, and using that as a visual aid helps a
lot when putting your schema together.


On Wed, Jul 8, 2009 at 8:08 AM, iFeghali  wrote:

>
> Hello All,
>
> I am stuck at a circular relationship problem. This is my scenario:
>
> - Machine HABTM Service HABTM Machine
> - Machine belongsTo Type hasMany Machine
> - Machine belongsTo Category hasMany Machine
> - Service belongsTo Customer hasMany Service
>
> So far so good. When the user goes to /machine/view it expects to see:
>
> [level 0] machine
> [level 1] machine type
> [level 1] machine category
> [level 1] services
> [level 2] services customers
>
> If I set recursive to 1, the last item will not be retrieved. If i set
> recursive to 2, everything goes well except I get machine records for
> type, category and services (too much unwanted data).
>
> I could let recursive = 2 and manually unbind machine from all other
> models in the view action, but that would be too much extra code for
> something apparently simple. note that the given scenario is just an
> exemplification, my real case has around 8 models tied on a complex
> "web".
>
> I could also made relationships one way only, but obviously it would
> break the views for the other models.
>
> so my question is whether i can set recursive to 2, but tells cake not
> to retrieve the main model thus preventing "circular data".
>
> Thank you.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to prevent circular relationships ?

2009-07-08 Thread brian

Have you tried using Containable? It's much usually easier to work
with than relying on 'recursive'.

On Wed, Jul 8, 2009 at 11:08 AM, iFeghali wrote:
>
> Hello All,
>
> I am stuck at a circular relationship problem. This is my scenario:
>
> - Machine HABTM Service HABTM Machine
> - Machine belongsTo Type hasMany Machine
> - Machine belongsTo Category hasMany Machine
> - Service belongsTo Customer hasMany Service
>
> So far so good. When the user goes to /machine/view it expects to see:
>
> [level 0] machine
> [level 1] machine type
> [level 1] machine category
> [level 1] services
> [level 2] services customers
>
> If I set recursive to 1, the last item will not be retrieved. If i set
> recursive to 2, everything goes well except I get machine records for
> type, category and services (too much unwanted data).
>
> I could let recursive = 2 and manually unbind machine from all other
> models in the view action, but that would be too much extra code for
> something apparently simple. note that the given scenario is just an
> exemplification, my real case has around 8 models tied on a complex
> "web".
>
> I could also made relationships one way only, but obviously it would
> break the views for the other models.
>
> so my question is whether i can set recursive to 2, but tells cake not
> to retrieve the main model thus preventing "circular data".
>
> Thank you.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



How to prevent circular relationships ?

2009-07-08 Thread iFeghali

Hello All,

I am stuck at a circular relationship problem. This is my scenario:

- Machine HABTM Service HABTM Machine
- Machine belongsTo Type hasMany Machine
- Machine belongsTo Category hasMany Machine
- Service belongsTo Customer hasMany Service

So far so good. When the user goes to /machine/view it expects to see:

[level 0] machine
[level 1] machine type
[level 1] machine category
[level 1] services
[level 2] services customers

If I set recursive to 1, the last item will not be retrieved. If i set
recursive to 2, everything goes well except I get machine records for
type, category and services (too much unwanted data).

I could let recursive = 2 and manually unbind machine from all other
models in the view action, but that would be too much extra code for
something apparently simple. note that the given scenario is just an
exemplification, my real case has around 8 models tied on a complex
"web".

I could also made relationships one way only, but obviously it would
break the views for the other models.

so my question is whether i can set recursive to 2, but tells cake not
to retrieve the main model thus preventing "circular data".

Thank you.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---