I have a hybrid type HABTM using the alternate method as described in the
Cookbook with hasMany and belongsTo associations. Now what would have been
the standard HABTM table now has additional '_id' fields. 

 

So the User can select a "Supply" by choosing a "Quantity" from drop down
menu of options. If no quantity selected then that supply is not saved as a
record. So for example on any save I might get

 

Array(

[0] => array(

 [profile_id] => 465465654654,

[supply_id] => 1,

[quantity_id] => 5),

 

[1] => array(

[profile_id] => 465465654654,

[supply_id] => 2,

[quantity_id] => 6), 

 

[2] => array(

[profile_id] => 465465654654,

[supply_id] => 3,

[quantity_id] => 7)

)

 

Ok all fine and good. Now user wants to make some changes to the saved
selections. Traditional HABTM deletes all records then saves all over again.
My Question is there a simple way to check that for example if the updated
array looked like:

 

Array(

//same

[0] => array(

[profile_id] => 465465654654,

[supply_id] => 1,

[quantity_id] => 5),

 

//changed

[1] => array(

[profile_id] => 465465654654,

[supply_id] => 2,

[quantity_id] => 5), 

 

 //original [2] no longer selected adding supply_id 4

[2] => array(

[profile_id] => 465465654654,

[supply_id] => 4,

[quantity_id] => 5)

 

) 

Where the original data [0] is the same so no need to delete, [1] has
changed, original  so update that record [2] has been deleted so delete from
db and

The new [2] needs to be added. So if the same do nothing, changed then
update, no longer there then remove, and if new add to the db. 

 

I just been testing the same page making changes and in a matter of  few
mins I went from id 1 to 1200 just testing 1 user. Since there are 10
supply_id's x 6 quantity_id's that 60 possible selection variations times
who knows what the math is on combination of the selections picked.you could
end up deleteing 10 records every save and adding 10 new ones. Figured it
would be easier to just update the selections.

 

Thoughts? Ideas? Opinions?

 

Thanks,

 

Dave

 

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

Reply via email to