Re: Dependent models

2010-04-26 Thread etipaced
Pablo,

The relationships you create in Cake are handled by setting any of the
following model properties:

- hasOne
- hasMany
- belongsTo
- hasAndBelongsToMany

You are probably familiar with this already if you're using Cake at
all. The relationships don't require the database tables themselves to
have foreign key constraints. In fact, in all of my applications, I do
not have constraints between my database tables in MySQL. In MySQL's
eyes, all my tables are 100% independent of each other.

Instead, I relate all my tables together at the application level.
Specifically, at the model level. This enables me to use all of Cake's
power such as dependent = true and the delete callbacks.

By relating your tables together at the model layer in Cake, and
setting dependent = true (valid for hasOne and hasMany only, btw),
Cake will automatically find the related records and delete them for
you even though MySQL does not have these tables connected with a
foreign key constraint.

HTH

- Kevin (etipaced)

On Apr 10, 9:03 pm, Pablo Vergara B. pabloandre...@gmail.com
wrote:
 How do you actually can use database CASCADE deleting method when no
 real relations are made into the database diagram? (Because
 relations are handled internally by cakePHP)

 I'm still a novice about cakePHP so I can be wrong... or not. Let's
 wait for a advanced user to answer both questions :).

 Inf fact (if we could) the database engine deleting/updating option
 (using CASCADE for instance) would be the fastest way to do this.

 Greetings and sorry if my english is not too good plz, I'm from a
 spanish speaking country...

 On Apr 10, 12:45 pm, Mateusz Kaczanowski kangu...@gmail.com wrote:

  Hi guys,

  In CakePHP we delete related records by dependency in model. Which way us
  better

  1. Set up CASCADE in innodb mysql database
  2. Usedependentin cakePHP model

  Better - I mean faster , safer .

  Thanks for answers

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Dependent models

2010-04-26 Thread Jeremy Burns
I would ALWAYS add database relationships because (i) it will perform a lot 
better (your database does not care or know that you are using Cake) and (ii) 
it is the ultimate safety net against bad deletes and orphan records.

Jeremy Burns
jeremybu...@me.com
On 27 Apr 2010, at 00:03, etipaced wrote:

 Pablo,
 
 The relationships you create in Cake are handled by setting any of the
 following model properties:
 
 - hasOne
 - hasMany
 - belongsTo
 - hasAndBelongsToMany
 
 You are probably familiar with this already if you're using Cake at
 all. The relationships don't require the database tables themselves to
 have foreign key constraints. In fact, in all of my applications, I do
 not have constraints between my database tables in MySQL. In MySQL's
 eyes, all my tables are 100% independent of each other.
 
 Instead, I relate all my tables together at the application level.
 Specifically, at the model level. This enables me to use all of Cake's
 power such as dependent = true and the delete callbacks.
 
 By relating your tables together at the model layer in Cake, and
 setting dependent = true (valid for hasOne and hasMany only, btw),
 Cake will automatically find the related records and delete them for
 you even though MySQL does not have these tables connected with a
 foreign key constraint.
 
 HTH
 
 - Kevin (etipaced)
 
 On Apr 10, 9:03 pm, Pablo Vergara B. pabloandre...@gmail.com
 wrote:
 How do you actually can use database CASCADE deleting method when no
 real relations are made into the database diagram? (Because
 relations are handled internally by cakePHP)
 
 I'm still a novice about cakePHP so I can be wrong... or not. Let's
 wait for a advanced user to answer both questions :).
 
 Inf fact (if we could) the database engine deleting/updating option
 (using CASCADE for instance) would be the fastest way to do this.
 
 Greetings and sorry if my english is not too good plz, I'm from a
 spanish speaking country...
 
 On Apr 10, 12:45 pm, Mateusz Kaczanowski kangu...@gmail.com wrote:
 
 Hi guys,
 
 In CakePHP we delete related records by dependency in model. Which way us
 better
 
 1. Set up CASCADE in innodb mysql database
 2. Usedependentin cakePHP model
 
 Better - I mean faster , safer .
 
 Thanks for answers
 
 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.
 
 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

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Dependent models

2010-04-11 Thread Pablo Vergara B.
How do you actually can use database CASCADE deleting method when no
real relations are made into the database diagram? (Because
relations are handled internally by cakePHP)

I'm still a novice about cakePHP so I can be wrong... or not. Let's
wait for a advanced user to answer both questions :).

Inf fact (if we could) the database engine deleting/updating option
(using CASCADE for instance) would be the fastest way to do this.

Greetings and sorry if my english is not too good plz, I'm from a
spanish speaking country...

On Apr 10, 12:45 pm, Mateusz Kaczanowski kangu...@gmail.com wrote:
 Hi guys,

 In CakePHP we delete related records by dependency in model. Which way us
 better

 1. Set up CASCADE in innodb mysql database
 2. Use dependent in cakePHP model

 Better - I mean faster , safer .

 Thanks for answers

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using remove me as the subject.


Re: Dependent models

2010-04-11 Thread Lucca Mordente
You really can't create this relation directly on the database. If you
want your DB to be faster, you must do it by your own, creating
foreing key indexes.

On Sunday, April 11, 2010, Pablo Vergara B. pabloandre...@gmail.com wrote:
 How do you actually can use database CASCADE deleting method when no
 real relations are made into the database diagram? (Because
 relations are handled internally by cakePHP)

 I'm still a novice about cakePHP so I can be wrong... or not. Let's
 wait for a advanced user to answer both questions :).

 Inf fact (if we could) the database engine deleting/updating option
 (using CASCADE for instance) would be the fastest way to do this.

 Greetings and sorry if my english is not too good plz, I'm from a
 spanish speaking country...

 On Apr 10, 12:45 pm, Mateusz Kaczanowski kangu...@gmail.com wrote:
 Hi guys,

 In CakePHP we delete related records by dependency in model. Which way us
 better

 1. Set up CASCADE in innodb mysql database
 2. Use dependent in cakePHP model

 Better - I mean faster , safer .

 Thanks for answers

 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.

 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

 To unsubscribe, reply using remove me as the subject.


-- 
Lucca Mordente

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Dependent models

2010-04-11 Thread Lucca Mordente
These internal database relations are not created by CakePHP, really.
If you want your database to faster, you must do it by your own,
creating foreign key indexes.

On 11 abr, 08:40, Lucca Mordente luccamorde...@gmail.com wrote:
 You really can't create this relation directly on the database. If you
 want your DB to be faster, you must do it by your own, creating
 foreing key indexes.

 On Sunday, April 11, 2010, Pablo Vergara B. pabloandre...@gmail.com wrote:





  How do you actually can use database CASCADE deleting method when no
  real relations are made into the database diagram? (Because
  relations are handled internally by cakePHP)

  I'm still a novice about cakePHP so I can be wrong... or not. Let's
  wait for a advanced user to answer both questions :).

  Inf fact (if we could) the database engine deleting/updating option
  (using CASCADE for instance) would be the fastest way to do this.

  Greetings and sorry if my english is not too good plz, I'm from a
  spanish speaking country...

  On Apr 10, 12:45 pm, Mateusz Kaczanowski kangu...@gmail.com wrote:
  Hi guys,

  In CakePHP we delete related records by dependency in model. Which way us
  better

  1. Set up CASCADE in innodb mysql database
  2. Use dependent in cakePHP model

  Better - I mean faster , safer .

  Thanks for answers

  Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
  with their CakePHP related questions.

  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 
  athttp://groups.google.com/group/cake-php?hl=en

  To unsubscribe, reply using remove me as the subject.

 --
 Lucca Mordente

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Dependent models

2010-04-10 Thread Mateusz Kaczanowski
Hi guys,

In CakePHP we delete related records by dependency in model. Which way us
better

1. Set up CASCADE in innodb mysql database
2. Use dependent in cakePHP model

Better - I mean faster , safer .

Thanks for answers

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using remove me as the subject.


Re: Dependent models

2010-04-10 Thread Lucca Mordente
The faster is using cascade, because it handled at a lower level than
the application level.
However, it's safer to delete related model through dependent,
specially when this model implements a beforeDelete or afterDelete
callbacks (do not forhet the attached behaviors). When it's not
handled by the app, these callbacks won't be called.

Hope this help!

On 10 abr, 13:45, Mateusz Kaczanowski kangu...@gmail.com wrote:
 Hi guys,

 In CakePHP we delete related records by dependency in model. Which way us
 better

 1. Set up CASCADE in innodb mysql database
 2. Use dependent in cakePHP model

 Better - I mean faster , safer .

 Thanks for answers

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using remove me as the subject.


Deleting dependent models with conditions

2008-06-07 Thread floob

Has anyone ever deleted from a Model that has dependent joins with
conditions, and realized that more rows got deleted than they
expected?

To give an example, let's declare 3 classes, Book Cd and
OverallFavorite.  OverallFavorite stores your prioritized rank of all
of your favorite stuff ... favorite book, cd, bike, framework,
whatever.  So, since we're joining many models to a single model, in
addition to a foreign key ID, the OverallFavorite model ALSO needs to
store which table that ID is references (classic compound key
situation).

The Book class would look like:

Book extends AppModel{
   ...
   var $hasOne = array('OverallFavorite' = array('foreignKey' =
'model_id', 'dependent' = true, 'conditions' =
'OverallFavorite.model_type = Book' );
   ...
}

What happens is, if you delete a book entry, the conditions aren't
being used.  EVERY row in OverallFavorite with the same foreignKey id
gets deleted.  If you have Cd, Book, and Framework, all with id=1 in
their tables, all three of those entries are deleted.

I ran into this yesterday, almost wrote up a new ticket ticket, and
found a 4-month old bug that was closed (not solved) with the
identical description.  I tacked on a test case to push that ticket
along, but I'm still curious about this bug.  So, my questions are:
Has anyone else had this problem before?  Is anyone EXPECTING this
delete-happy behavior to happen?  Is there some other understood
workaround for this?

Thanks all,
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Deleting dependent models with conditions

2008-06-07 Thread floob

Almost forgot ... here's the link to the ticket: 
https://trac.cakephp.org/ticket/4202

On Jun 7, 1:42 pm, floob [EMAIL PROTECTED] wrote:
 Has anyone ever deleted from a Model that has dependent joins with
 conditions, and realized that more rows got deleted than they
 expected?

 To give an example, let's declare 3 classes, Book Cd and
 OverallFavorite.  OverallFavorite stores your prioritized rank of all
 of your favorite stuff ... favorite book, cd, bike, framework,
 whatever.  So, since we're joining many models to a single model, in
 addition to a foreign key ID, the OverallFavorite model ALSO needs to
 store which table that ID is references (classic compound key
 situation).

 The Book class would look like:

 Book extends AppModel{
...
var $hasOne = array('OverallFavorite' = array('foreignKey' =
 'model_id', 'dependent' = true, 'conditions' =
 'OverallFavorite.model_type = Book' );
...

 }

 What happens is, if you delete a book entry, the conditions aren't
 being used.  EVERY row in OverallFavorite with the same foreignKey id
 gets deleted.  If you have Cd, Book, and Framework, all with id=1 in
 their tables, all three of those entries are deleted.

 I ran into this yesterday, almost wrote up a new ticket ticket, and
 found a 4-month old bug that was closed (not solved) with the
 identical description.  I tacked on a test case to push that ticket
 along, but I'm still curious about this bug.  So, my questions are:
 Has anyone else had this problem before?  Is anyone EXPECTING this
 delete-happy behavior to happen?  Is there some other understood
 workaround for this?

 Thanks all,
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---