PHPackages                             macagua/yii-cadvancedarbehavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. macagua/yii-cadvancedarbehavior

ActiveYii-extension[Database &amp; ORM](/categories/database)

macagua/yii-cadvancedarbehavior
===============================

Fork of Yii 1.1 CAdvancedArBehavior (Advanced functions for Active Record implementation) by thyseus

281PHP

Since Jul 29Pushed 10y ago1 watchersCompare

[ Source](https://github.com/macagua/yii-cadvancedarbehavior)[ Packagist](https://packagist.org/packages/macagua/yii-cadvancedarbehavior)[ RSS](/packages/macagua-yii-cadvancedarbehavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii-cadvancedarbehavior
=======================

[](#yii-cadvancedarbehavior)

Fork of Yii 1.1 CAdvancedArBehavior (Advanced functions for Active Record implementation) by thyseus.

Yii 1.1: cadvancedarbehavior
----------------------------

[](#yii-11-cadvancedarbehavior)

The CAdvancedArBehavior extension adds up some functionality to the default possibilites of yii´s ActiveRecord implementation. At the moment it is able to automatically save MANY\_MANY relation objects when save()-ing an Object.

### Changelog [¶](#hh0)

[](#changelog-)

Version 0.3 added 25. 05. 2011 by thyseus

- added $ignoreRelations to ignore specified relations. The Behavior will take all found many2many relations by default. Specify exceptions in this array.
- fixes all the bugs and glitches found in the discussion

### Resources [¶](#hh1)

[](#resources-)

- [Join discussion](http://www.yiiframework.com/forum/index.php?/topic/6905-please-test-my-ar-enhancement-automatically-sync-many-many-table-when-calling-save/)

Documentation [¶](#hh2)
-----------------------

[](#documentation-)

### Requirements [¶](#hh3)

[](#requirements-)

- Yii 1.1 or above

### Installation [¶](#hh4)

[](#installation-)

To use this extension, just copy this file to your extensions/ directory, add 'import' =&gt; 'application.extensions.CAdvancedArBehavior', \[...\] to your config/main.php and add this behavior to each model you would like to inherit the new possibilities.

### Usage [¶](#hh5)

[](#usage-)

```
public function behaviors(){
          return array( 'CAdvancedArBehavior' => array(
            'class' => 'application.extensions.CAdvancedArBehavior'));
          }

```

### Possibilities so far: [¶](#hh6)

[](#possibilities-so-far-)

### Better support of MANY\_TO\_MANY relations: [¶](#hh7)

[](#better-support-of-many_to_many-relations-)

When we have defined a MANY\_MANY relation in our relations() function, we are now able to add up instances of the foreign Model on the fly while saving our Model to the Database. Let´s assume the following Relation:

Post has: 'categories'=&gt;array(self::MANY\_MANY, 'Category', 'tbl\_post\_category(post\_id, category\_id)')

Category has: 'posts'=&gt;array(self::MANY\_MANY, 'Post', 'tbl\_post\_category(category\_id, post\_id)')

Now we can use the attribute 'categories' of our Post model to add up new rows to our MANY\_MANY connection Table:

```
$post = new Post();
$post->categories = Category::model()->findAll();
$post->save();

```

This will save our new Post in the table Post, and in addition to this it updates our N:M-Table with every Category available in the Database.

We can further limit the Objects given to the attribute, and can also go the other Way around:

```
 $category = new Category();
 $category->posts = array(5, 6, 7, 10);
 $category->save();

```

We can pass Object instances like in the first example, or a list of integers that representates the Primary key of the Foreign Table, so that the Posts with the id 5, 6, 7 and 10 get´s added up to our new Category.

5 Queries will be performed here, one for the Category-Model and four for the N:M-Table tbl\_post\_category. Note that this behavior could be tuned further in the future, so only one query get´s executed for the MANY\_MANY Table.

We can also pass a *single* object or an single integer:

```
 $category = new Category();
 $category->posts = Post::model()->findByPk(12);
 $category->posts = 12;
 $category->save();

```

Change Log [¶](#hh8)
--------------------

[](#change-log-)

### January 30, 2010 [¶](#hh9)

[](#january-30-2010-)

Version 0.2 Code Cleanup, Bugfixes and added save() support

### January 28, 2010 [¶](#hh10)

[](#january-28-2010-)

- Initial release.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b70c1686a2fb041338958638f8072458a5e405c968d215e1cfbacaef79dcda8?d=identicon)[macagua](/maintainers/macagua)

---

Top Contributors

[![macagua](https://avatars.githubusercontent.com/u/185395?v=4)](https://github.com/macagua "macagua (5 commits)")

---

Tags

phpyiiyii-cadvancedarbehavior

### Embed Badge

![Health badge](/badges/macagua-yii-cadvancedarbehavior/health.svg)

```
[![Health](https://phpackages.com/badges/macagua-yii-cadvancedarbehavior/health.svg)](https://phpackages.com/packages/macagua-yii-cadvancedarbehavior)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
