github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

teknoid / cakephp-habtamable-behavior

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 14
    • 4
  • Source
  • Commits
  • Network (4)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Lessens HABTM pains — Read more

  cancel

http://teknoid.wordpress.com

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Updates to README 
teknoid (author)
Thu Oct 08 13:36:34 -0700 2009
commit  fbbb4b08844575d2e40e0621104d0b6a5fc1c501
tree    25501b3e607951d68b78ff1f0385e21493c07d65
parent  5aa1b870cbbbaf74b0f08853903ccb0e830db8b6
cakephp-habtamable-behavior /
name age
history
message
file README.md Thu Oct 08 13:36:34 -0700 2009 Updates to README [teknoid]
directory models/ Thu Oct 08 13:18:59 -0700 2009 Refactoring of behavior logic in some places Ab... [teknoid]
README.md

Habtamable behavior (!!! Still alpha, quite a few to-do's !!!)

Save two HABTM models at once

For example you are saving a Location (my sweet penthouse) with all the relevant info and the Address (the actual address of the penthouse).

Example: $this->Location->saveAll($this->data); In the above example Location and Address will be saved with transactional support. (FYI save() works just as well.)

Search accross HABTM models

For example, you can do something like: $this->Location->find('all', array('conditions' => array('Location.is_active' => 1, 'Address.city' => 'Miami')));

(The searching works by "faking" a hasOne bind, and therefore building a join to specify conditions. For the time being only INNER join is supported and the bind is not permament.)

Of couse, Location HABTM Address

Features (so far):

  • If address (HABTM record) exists will use existing ID
  • Will ensure proper relationship saving
  • Model validation
  • Allows you to search across HABTM models

Very simple to use:

Using our example above, in the Location model, all you need to do is to add:
public $actsAs = array('Habtamable');

You can also pass some settings like so:
public $actsAs = array('Habtamable' => array('joinType' => 'LEFT', 'fieldsToSkip' => array('this', 'that'), 'habtmModel' => 'SomeModel'));

'joinType' -> default is "INNER", any valid SQL JOIN type should be supplied. This is used when doing cross-model queries.
'fieldsToSkip' -> do not include these fields, when checking for an exising record. The setting will be merged with defaults set in the behavior.
'habtmModel' -> related HABTM model, if not provided the first model in the association is used.

The above presumes that in the Location model definition you have:
public $hasAndBelongsToMany = array('Address');

The rest is taken care of for you.

Suggestions, improvments, etc. are needed. Contact here

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server