Copyable Behavior

By Jamie Nay (jpnay)
Copyable Behavior adds the ability to copy a model record, including all hasMany and hasAndBelongsToMany
associations. Copyable relies on Containable behavior, which this behavior will attach on the fly as needed. HABTM relationships are just duplicated in the join table, while hasMany and hasOne records are recursively copied as well.
Copyable adds a copy() function to your model, which you can use to copy (that is, create a duplicate of) a record and any of its hasOne, hasMany, or hasAndBelongsToMany relationships. In the case of hasOne and hasMany, those records are recursively copied as well. For example, if you want to copy a LinkCategory that hasMany Link, all of the Link records will be copied. The copy is fully recursive, meaning that if Link HasMany Comment, then all of those records will be copied as well. In the case of HABTM associations, only the join table rows are copied, not the associated records. The copy() function takes one argument – the ID of the record you wish to copy.

The code is on page two, but the most current version is kept on Github: http://github.com/jamienay/copyable_behavior
Copyable uses Containable to help generate its queries, but don’t worry – it’ll attach Containable if it can’t find it on the model.

A handful of config options:

* recursive: whether to copy hasOne- and hasMany-associated models (default: true)
* habtm: whether to copy hasAndBelongsToMany relationships (default: true)
* stripFields: an array model fields that should ignored when copying (default: id, created, modified, lft, rght)

After attaching Copyable to a model via the $actsAs array – I recommend putting it on AppModel – usage is as simple as:

Download code
// From a controller method
$this->MyModel->copy($id);
 
// From a model method
$this->copy($id);

Page 2: The Code

Comments 1440

CakePHP Team Comments Author Comments
 

Comment

1 Page 2?

is there any reason the page 2 code cant be put in this thread?
Purchase Insurance
Posted Jul 15, 2010 by jim jones
 

Comment

2 thank you

I hope you find this component useful. If you like the component, find a bug, or have a feature request please post a comment.

Thanks,
Porno izle
Posted Jul 17, 2010 by ahmet
 

Comment

3 food for thought

Behavior is all about copying! Since birth till death. wihtout copying there is no behavior, just ponder over it well, you will get the key to successful living!

Passion RX
Posted Jul 18, 2010 by bad anooj
 

Comment

4 film indir

film indir thank you admin..
Posted Jul 18, 2010 by maxilla
 

Comment

5 creativity

Forex trading is exciting and potentially very profitable, but can carry risk if you’re not careful. Fortunately some of the tools available now make it very possible to cut the risks associated with FX trading and still turn a good profit. if you can get over fear of the unknown theres nothing standing between you and great profits. online forex trading works.

Seriously I’m really excited about learning more about the forex trading game - if you’re a forex trader I’d love to hear from you and compare notes - if you’ve used an automated forex trading system or a forex demo account to trade I want to hear how it went from you as well. Automated forex trading is the way of the future I think, great passive income.
Posted Jul 18, 2010 by jim jones
 

Comment

6 Re:

Interesting post. I have been wondering about this issue,so thanks for posting.logo designs
Posted Jul 19, 2010 by summer bell
 

Comment

7 behavior

Behavior is all about copying! Since birth till death. wihtout copying there is no behavior, just ponder over it well, you will get the key to successful living!


suppliers network
Posted Jul 20, 2010 by bad anooj
 

Comment

8 nice

To reproduce this bug, take any object you didn't make yourself, but can at least copy, drop it on the ground and shift copy it. Now inspect your new object, despite the fact you're not the creator, all the creation dates of the object's prims have been reset to the time of the copy. This is especially bad for people tracking possible copybotting. Previous to early 2008 you could not change the creation date of ANY prim no matter how many times it was copied no matter the permissions. Let me make something else clear due to a comment. When you COPY an object it is not changing the creation date of the object, to do that you have to create it. I.E. copy Promotional Products is just that, duplication, not creation, creation means you are the originator, the one who made the object. This includes the child prims, it should not reset the creation date.
Posted Jul 21, 2010 by Joshimale
 

Comment

9 She

this is not just shorter/prettier, i got an error message inserting data for a model that joins another model with mysql complaining about the ambiguity of field 'id' - so we would need to at least change 'recursive' to -1 in your query to stop cake from performing any joins
Sex izLe Porno Seyret Porno izLe Sikiş Seyret Sex Videoları Kızlık Bozma Sikiş Sikiş izLe Sex Tx
Canlı Seks Sex Hikayeleri Sikiş izLe Sikiş Seyret Cinsel Sohbet Sex Sohbet Cinsel Sohbet Türk Porno
Posted Jul 22, 2010 by cokcici
   

Comment

11 ed

Because a lot of them have seen the beleivable way to improve that after awhile that it starts to look like the solution this morning. car shipping Yes, it has be gone over the best way.
Posted Jul 22, 2010 by dan kaylee
 

Comment

12 great!

Posted Jul 24, 2010 by Criação de sites
 

Comment

13 Copying feature is great

Thanks again,

Seth

at

Contractor Marketing

Posted Jul 25, 2010 by Seth Larrabee
 

Comment

14 thanks

thanks you admin. porno sikis porno izle film izle
Posted Jul 25, 2010 by Dware
 

Comment

15 is it free

موقع العاب العاب طبخ العاب بنات العاب سيارات العاب باربي العاب للبنات فقط العاب تلبيس العاب تلبيس بنات العاب بنات فقط العاب قص الشعر العاب اطفال العاب بنات جديدة العاب البنات العاب قص شعر العاب ترتيب تلبيس بنات العاب الطبخ العاب السيارات العاب مغامرات العاب اكشن العاب ذكاء العاب مسدسات العاب تصويب العاب سباق باربي مركز تحميل العاب جديدة العاب 2010 العاب سونيك العاب ميك اب العاب طرزان العاب مكياج العاب براتز العاب ديزني العاب دراجات العاب دبابات العاب فلاش دردشه العاب بنات قص شعر العاب هانا مونتانا العاب طبخ للبنات فقط العاب قص شعر للبنات فقط hguhf العاب hguhf 'fo hguhf fkhj hguhf sdhvhj hguhf مسجات توبيكات صور تفحيط فيديو منتديات القران الكريم محمد اناشيد الاسلامي خطب محاضرات ادعيه اناشيد طيور الجنة طيور الجنة صلاة التراويح العام النقاش الجاد منوعات الاصدقاء التوظيف الطب الصحه الشعر خواطر قصص الشعر الصوتي طبخ موضه المراة الطفل ديكور العروس ازياء مكياج منتديات العاب نكت الرياضه برامج الماسنجر العاب العاب سيارات العاب بنات العاب طبخ العاب ذكاء العاب اطفال العاب اكشن للبنات العاب مغامرات العاب المشاهير العاب الديكور العاب باربي العاب مكياج العاب قص الشعر العاب هانا مونتانا العاب تلوين العاب رياضية العاب مسلية العاب فلاش العاب مضحكة العاب تعليم العاب الغاز نكت 2010 ترفيه منتديات الرياضه برامج 2010 انترنت تطوير مواقع منتديات التصميم التصميم مسجات 2010 مسجات 2011 الجوال برامج الجوال ثيمات منتديات الماسنجر ماسنجر ماسنجر 2010 ماسنجر 2011 توبيكات 2010 توبيكات 2011 فيديو 2010 فيديو 2011 صور 2010 صور 2011 صور سيارات
Posted Jul 26, 2010 by ahmed said
 

Comment

16 burmeh yaza lida fx15 biber hapı ile formda girin

Posted Jul 31, 2010 by Fatih