Re: HABTM table models in alphabetical order required?

2014-07-10 Thread John Andersen
CakePHP allows you to use your own table names. Check that CakePHP book at: 
http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable
Enjoy, John

On Monday, 7 July 2014 18:20:19 UTC+3, Jamison Bryant wrote:
>
> Hi all,
>
> I'm developing an application that has Photos and Users. I've been using 
> CakePHP since 2.0, so I'm very familiar with HABTM conventions, including 
> the fact that the tables are named in alphabetical order by convention. In 
> my case, this would be photos_users, but I really hate that because it just 
> seems backward. My question is, will CakePHP break if I name the table 
> users_photos, which makes so much more sense?
>
> Thanks,
>
> Jamison
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: HABTM dropdown in add.ctp

2013-05-04 Thread Timon Guggenbuehl
solved

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: HABTM Inner Join with 3 models

2013-03-20 Thread Jerome Walitzek
Hello,
I solved the problem now as follows

*JobsController.php*
...
$drivers = $this->Job->query("SELECT User.id, (CONCAT(vorname, ' 
',nachname)) AS name FROM users AS User INNER JOIN users_events AS Event ON 
User.id = Event.user_id WHERE Event.event_id = $jobid");
...

*edit.ctp*
$select_value = array();
$select_value[null] = '-- Make a selection --';
foreach($drivers as $driver) {
$key = $driver['User']['id'];
$value   = $driver[0]['name'];
$select_value[$key]= $value;
}

$mydata = $this->data;
if ( $mydata['Job']['driver_id'] != null ) {
foreach ( $select_value as $k => $v ) {
if ( $mydata['Job']['driver_id'] == $k ) {
$this_is_selected =  $k; 
}
}
} else {
$this_is_selected = 0;
}
echo $this->Form->input('driver_id', array(
'options' => $select_value,
'type' => 'select',
'label' => 'Driver'
));

*add.ctp*
$select_value = array();
$select_value[null] = '-- Make a selection --';
foreach($drivers as $driver) {
$key = $driver['User']['id'];
$value   = $driver[0]['name'];
$select_value[$key]= $value;
}

echo $this->Form->input('driver_id', array(
'options' => $select_value,
'type' => 'select',
'label' => 'Driver'
));


Okay it's not CakeLike, but it works flawlessly.

Nice Greetings

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: HABTM Inner Join with 3 models

2013-03-19 Thread Jerome Walitzek

Am Dienstag, 19. März 2013 00:42:28 UTC+1 schrieb cricket:
>
> On Mon, Mar 18, 2013 at 12:40 PM, Jerome Walitzek 
> > wrote: 
> > Hi there, 
> > 
> > i have a problem with INNER JOIN. 
> > 
> > Models 
> > Job 
> > User 
> > UsersEvent 
>
> What are the associations between models? Do you also have an Event 
> model? I ask because that last one looks like a join model between 
> User & Event. (Although for Cake the table would conventionally be 
> named events_users -- models are alphabetical.) 
>

Of course i gave an Event Model to. Sorry i forgot.
Here are my associations between the models

*Event.php*
public $belongsTo = array(
'City' => array(
'className' => 'City',
'foreignKey' => 'city_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Dispatcher' => array(
'className' => 'User',
'foreignKey' => 'dispatcher_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Client' => array(
'className' => 'User',
'foreignKey' => 'client_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

public $hasMany = array(
'Job' => array(
'className' => 'Job',
'foreignKey' => 'event_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Location' => array(
'className' => 'Location',
'foreignKey' => 'city_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);

public $hasAndBelongsToMany = array(
'Location' => array(
'className' => 'Location',
'joinTable' => 'locations_events',
'foreignKey' => 'event_id',
'associationForeignKey' => 'location_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'User' => array(
'className' => 'User',
'joinTable' => 'users_events',
'foreignKey' => 'event_id',
'associationForeignKey' => 'user_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
);

*Job.php*
public $belongsTo = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'event_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
 'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
 'Driver' => array(
'className' => 'User',
'foreignKey' => 'driver_id',
'conditions' => '',
'fields' => '',
'order' => '',
),
 'UsersEvent' => array(
'className' => 'UsersEvent',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => '',
)
);

*User.php*
public $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'driver_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
 'Job' => array(
'className' => 'Job',
'foreignKey' => 'driver_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
 'UsersEvent' => array(
'className' => 'UsersEvent',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
);

*UsersEvent.php*
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Event' => array(
'className' => 'Event',
'foreignKey' => 'event_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Job' => array(
'className' => 'Job',
'foreignKey' => 'event_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

Any ideas how i could do it on CakeWay ?

Nice Greetings
Jerome

 

>
> You can use joins for hasOne and belongsTo assoc. One workaround is to 
> unbind the normal assoc. and temporarily bind on another. 
>
> > In my Job View i would like to get all users which are assigned to an 
> event. 
> > I only get successfully the IDs from UsersEvent but not the names from 
> the 
> > User Model. 
> > 
> > In principle I would like to do following: 
> > SELECT A.`id`,(CONCAT(A.vorname, ' ',A.nachname)) AS name FROM users AS 
> A 
> > INNER JOIN users_events AS U ON A.id = U.user_id WHERE U.event_id = 2 
> > 
> > But how i write it cake like ? 
> > 
> > When i try it with 
> > $this->Job->query("SELECT A.`id`,(CONCAT(A.vorname, ' ',A.nachname)) AS 
> name 
> > FROM users AS A INNER JOIN users_events AS U ON A.id = U.user_id WHERE 
> > U.event_id = 2"); 
> > i get the complete array in my select field and can´t select a name. 
> > 
> > Thanks for help 
>

Re: HABTM Inner Join with 3 models

2013-03-18 Thread lowpass
On Mon, Mar 18, 2013 at 12:40 PM, Jerome Walitzek
 wrote:
> Hi there,
>
> i have a problem with INNER JOIN.
>
> Models
> Job
> User
> UsersEvent

What are the associations between models? Do you also have an Event
model? I ask because that last one looks like a join model between
User & Event. (Although for Cake the table would conventionally be
named events_users -- models are alphabetical.)

You can use joins for hasOne and belongsTo assoc. One workaround is to
unbind the normal assoc. and temporarily bind on another.

> In my Job View i would like to get all users which are assigned to an event.
> I only get successfully the IDs from UsersEvent but not the names from the
> User Model.
>
> In principle I would like to do following:
> SELECT A.`id`,(CONCAT(A.vorname, ' ',A.nachname)) AS name FROM users AS A
> INNER JOIN users_events AS U ON A.id = U.user_id WHERE U.event_id = 2
>
> But how i write it cake like ?
>
> When i try it with
> $this->Job->query("SELECT A.`id`,(CONCAT(A.vorname, ' ',A.nachname)) AS name
> FROM users AS A INNER JOIN users_events AS U ON A.id = U.user_id WHERE
> U.event_id = 2");
> i get the complete array in my select field and can´t select a name.
>
> Thanks for help
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: HABTM Update existing models

2013-02-15 Thread Mateusz Kapusta
Hi, you should try to get your data in an array structured as  follows:

[User]

[id] => int

[Book]

[0] => book1id

[1]=> book2id

and save your data with a saveAssociated($array) call. Tell me if it works! 

 

 


Il giorno lunedì 1 settembre 2008 09:03:40 UTC+2, Graham Weldon ha scritto:
>
> Hey all, 
>
> I've been digging for a good example for exactly what I am trying to 
> do. 
> Most of the samples out there I can find are for HABTM relationships 
> adding and updating, whilst adding a new model instance. 
>
> What I am after is the update process / procedure required to update 
> the association table only, for a couple of existing models. I have a 
> User management Section, and a Book management section. A user cannot 
> add books, and their registration process is separated for 
> authorisation / verification reasons. 
>
> Once logged in, they should be able to associate a book to their user 
> model, from the list of existing books. 
>
> Can someone point me to an example of this kind of HABTM update? 
>
> Much appreciated. 
> Cheers. 
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: HABTM round trip query

2013-02-10 Thread lowpass
I forgot the Language model to get the *other* langs the artist uses.

public function getArtistsForLang($lang)
{
return $this->find(
'all',
array(
'conditions' => array(
$this->alias.'.code' => $lang
),
'contain' => array(
'Artist' => array(
'ArtistsLanguage' => array(
'Language'
)
)
)
)
);
}

On Sun, Feb 10, 2013 at 8:53 PM, lowpass  wrote:
> Try this. I'm assuming your languages table has a 'code' column and
> the request passes a 2-letter string for the code for the desired
> language. That's probably how I'd do it but you may need to modify for
> your own setup.
>
> (This would be in the Language model.)
>
> public function getArtistsForLang($lang)
> {
> return $this->find(
> 'all',
> array(
> 'conditions' => array(
> $this->alias.'.code' => $lang
> ),
> 'contain' => array(
> 'Artist' => array(
> 'ArtistsLanguage'
> )
> )
> )
> );
> }
>
> This could be improved by specifying joins to reduce the number of queries.
>
> On Sun, Feb 10, 2013 at 7:25 AM, crouch...@googlemail.com
>  wrote:
>> Hi all,
>>
>> If this topic is covered, sorry, but I don't really know what to search
>> under and all my searches resulted in nothing.
>>
>> Background:
>> Developing a site for a voice over company.
>>
>> Requirement:
>> Voice artists can have several different languages and languages can have
>> several different voice artists, each artist can have a playable recording
>> for each language.
>>
>> What am I doing:
>> Searching for all artists that can speak a given language, but want to know
>> what languages they also speak.
>>
>> Basic search:
>> $this->Language->find('all');
>>
>> Result
>> Language->Artist->ArtistsLanguage<-- Only the record to the language is
>> resulting.
>>
>> Desire
>> Language->Artist->Language->array(record 1->ArtistsLanguage, record
>> 2->ArtistsLanguage, etc...)
>>
>> Comments:
>> Basically, I am looking to find all artists for a given language. This part
>> works, but the result for the list of languages that the artists speaks only
>> results in the HABTM model record belonging to the artist.
>>
>> How can a do a round trip in a HABTM relationship?
>>
>> Thanks for all the help,
>> Jay
>> Result:
>>
>> --
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to cake-php+unsubscr...@googlegroups.com.
>> To post to this group, send email to cake-php@googlegroups.com.
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: HABTM round trip query

2013-02-10 Thread lowpass
Try this. I'm assuming your languages table has a 'code' column and
the request passes a 2-letter string for the code for the desired
language. That's probably how I'd do it but you may need to modify for
your own setup.

(This would be in the Language model.)

public function getArtistsForLang($lang)
{
return $this->find(
'all',
array(
'conditions' => array(
$this->alias.'.code' => $lang
),
'contain' => array(
'Artist' => array(
'ArtistsLanguage'
)
)
)
);
}

This could be improved by specifying joins to reduce the number of queries.

On Sun, Feb 10, 2013 at 7:25 AM, crouch...@googlemail.com
 wrote:
> Hi all,
>
> If this topic is covered, sorry, but I don't really know what to search
> under and all my searches resulted in nothing.
>
> Background:
> Developing a site for a voice over company.
>
> Requirement:
> Voice artists can have several different languages and languages can have
> several different voice artists, each artist can have a playable recording
> for each language.
>
> What am I doing:
> Searching for all artists that can speak a given language, but want to know
> what languages they also speak.
>
> Basic search:
> $this->Language->find('all');
>
> Result
> Language->Artist->ArtistsLanguage<-- Only the record to the language is
> resulting.
>
> Desire
> Language->Artist->Language->array(record 1->ArtistsLanguage, record
> 2->ArtistsLanguage, etc...)
>
> Comments:
> Basically, I am looking to find all artists for a given language. This part
> works, but the result for the list of languages that the artists speaks only
> results in the HABTM model record belonging to the artist.
>
> How can a do a round trip in a HABTM relationship?
>
> Thanks for all the help,
> Jay
> Result:
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: HABTM Join Table Entries Disappearing

2012-12-05 Thread crush
Thanks guys for your help.

I think that I have found what is causing the problem but I need some 
feedback to see if it's probable.

Lets say I have the models 'Order' and 'Cart' which have a HABTM 
relationship with a join model 'CartsOrder'.

*When I run this:*

$order = $this->Order->find('first');
$this->Order->save($order);


*It will:*

1) UPDATE the orders table
2) DELETE all of the joins in the 'carts_orders' table
3) INSERT the new joins to the 'carts_orders' table, one by one.


That seems to work properly but what if I ran the above code multiple times 
at once? What if the find was called before the last instance of done 
writing all the inserts? You would get an incomplete find and then the save 
after that would not write the missing joins. That would result in missing 
joins.

Thoughts?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM and user login

2012-10-29 Thread lowpass
That's what I've done in the past when I want to include data that
Auth doesn't automatically store. IIRC, you can write to the Auth.User
key; the data will then be available from the user() method.

$this->Session->write('Auth.User.group', $group_data);

Retrieve with $this->Auth->user('group')

On Fri, Oct 26, 2012 at 5:45 AM, Álvaro G. Vicario
 wrote:
> I have a User model to use built-in authentication. The model has several
> $hasOne relationships and all linked models get saved automatically into
> session, which is great because I can call AuthComponent::user() whenever I
> need to perform an action based on user data.
>
> Now, I've added a $hasAndBelongsToMany relationship to indicate that a user
> can belong to zero or more groups. However, information about the Group
> model doesn't show up anywhere in the Auth component. I can definitively
> perform a manual User->find() and groups will be there but
> AuthComponent::user() does not contain group information. I've tried
> everything I could think of, including the contain option. I know I'm using
> contain right because it makes valid models appear and it complains for
> non-existant models, but Group is simply ignored.
>
> In the end I had to write a hack in my login function: make a manual find()
> and incorporate the 'Group' key to session data.
>
> Is this a known limitation?
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM Join Table Entries Disappearing

2012-10-11 Thread rchavik


On Thursday, October 11, 2012 10:53:07 PM UTC+7, keith...@classoutfit.com 
wrote:
>
> For 2.x sites you can also set 'unique' => 'keepExisting' to prevent the 
> save from deleting existing records:
>

Yes.

However, you will still need to ensure that those data exist on the form 
(which might not be required).

For example: User habtm Role.
When updating a User address, you still need to provide the Role data in 
the POSTed array.  To avoid the need
of providing the Role data, you could temporarily unbind the relationship 
using unbindModel() before the call to User->save().

 

>
>
> http://book.cakephp.org/2.0/en/models/saving-your-data.html#what-to-do-when-habtm-becomes-complicated
>
> http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#ref-habtm-arrays
>
> Keith Gorman
> *Class Outfit*
> **
> www.classoutfit.com
>  
> On 11 Oct 2012, at 08:15, Jeremy Burns | Class Outfit <
> jerem...@classoutfit.com > wrote:
>
> By default, Cake clears down the entire habtm table (for the current 
> association) and adds back in just those that are in the current saved 
> dataset. So if a cart has three orders and you try to add another in 
> isolation the first three are cleared and replaced with the new one. If you 
> are trying to add just a new cart_order and want to preserve the existing 
> ones you are best off creating a model for the habtm table and managing it 
> just as you would any other model.
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com 
>
> On 10 Oct 2012, at 22:03:26, crush > wrote:
>
> Hey,
> I have an orders table, a carts table and a carts_orders table. Every once 
> and a while, I lose some of the rows from the carts_orders table. They are 
> being created properly but are being deleted at some point. I have been 
> trying to figure it out but everything in the applications works 99.9 
> percent of the time and it's very difficult to nail down exactly what's 
> happening. 
>
> My questions is: *What CakePHP methods would cause those rows to be 
> deleted, but not the associated entries in the carts and orders tables*?
>
> Any help would be appreciated!
>
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake...@googlegroups.com
> .
> To unsubscribe from this group, send email to 
> cake-php+u...@googlegroups.com .
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  
>
>
>
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake...@googlegroups.com
> .
> To unsubscribe from this group, send email to 
> cake-php+u...@googlegroups.com .
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM Join Table Entries Disappearing

2012-10-11 Thread Keith Gorman | Class Outfit
For 2.x sites you can also set 'unique' => 'keepExisting' to prevent the save 
from deleting existing records:

http://book.cakephp.org/2.0/en/models/saving-your-data.html#what-to-do-when-habtm-becomes-complicated
http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#ref-habtm-arrays

Keith Gorman
Class Outfit

www.classoutfit.com

On 11 Oct 2012, at 08:15, Jeremy Burns | Class Outfit 
 wrote:

By default, Cake clears down the entire habtm table (for the current 
association) and adds back in just those that are in the current saved dataset. 
So if a cart has three orders and you try to add another in isolation the first 
three are cleared and replaced with the new one. If you are trying to add just 
a new cart_order and want to preserve the existing ones you are best off 
creating a model for the habtm table and managing it just as you would any 
other model.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 10 Oct 2012, at 22:03:26, crush  wrote:

> Hey,
> I have an orders table, a carts table and a carts_orders table. Every once 
> and a while, I lose some of the rows from the carts_orders table. They are 
> being created properly but are being deleted at some point. I have been 
> trying to figure it out but everything in the applications works 99.9 percent 
> of the time and it's very difficult to nail down exactly what's happening. 
> 
> My questions is: What CakePHP methods would cause those rows to be deleted, 
> but not the associated entries in the carts and orders tables?
> 
> Any help would be appreciated!
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
--- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM Join Table Entries Disappearing

2012-10-11 Thread Marcus James
If you are using $this->CartsOrder->delete(); then it must be deleting the
cartsorder record . You should check for that.




Enjoy,
Marcus

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM Join Table Entries Disappearing

2012-10-11 Thread Jeremy Burns | Class Outfit
By default, Cake clears down the entire habtm table (for the current 
association) and adds back in just those that are in the current saved dataset. 
So if a cart has three orders and you try to add another in isolation the first 
three are cleared and replaced with the new one. If you are trying to add just 
a new cart_order and want to preserve the existing ones you are best off 
creating a model for the habtm table and managing it just as you would any 
other model.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 10 Oct 2012, at 22:03:26, crush  wrote:

> Hey,
> I have an orders table, a carts table and a carts_orders table. Every once 
> and a while, I lose some of the rows from the carts_orders table. They are 
> being created properly but are being deleted at some point. I have been 
> trying to figure it out but everything in the applications works 99.9 percent 
> of the time and it's very difficult to nail down exactly what's happening. 
> 
> My questions is: What CakePHP methods would cause those rows to be deleted, 
> but not the associated entries in the carts and orders tables?
> 
> Any help would be appreciated!
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM save Question

2012-09-10 Thread gloop
Hi, sorry for my late response.

I tested some ways and now i can save/edit.

  public function edit($id = null){
if(empty($id)) $this->redirect('index');
if(!$this->request->is('get')){
  $data = $this->request->data;
  $this->Translation->save($data['Translation']);
  $_data = array();
  foreach($data['Language'] as $key => $value){
  $_data[] = array(
  'id' => $value['LanguagesTranslation']['id'],
  'translation_id' => $id,
'language_id' => $value['id'],
  'value' => $value['LanguagesTranslation']['value']
  );
  }
  $this->Translation->LanguagesTranslation->saveAll($_data);
  $this->redirect('index');
}

$this->Translation->id = $id;
$r = $this->Translation->read();
$this->request->data = $r;
$this->loadModel('Language');
$this->set('languages', $this->Language->find('all'));
  }

Thats ok, but i dont know how i can validate the joinTable, cause i must 
call 2 save functions.

Well ... maybe u know a better way,

On Friday, September 7, 2012 5:25:17 AM UTC+2, Mohammad Naghavi wrote:
>
> Hi Steffen,
> what is wrong with
> $this->Translation->LanguagesTranslation->save()
>
> that you need a better way?
>
>
> On Thu, Sep 6, 2012 at 3:25 PM, gloop > wrote:
>
>> Hello,
>>
>> is there a way to save directly to the joining table? Like the find data?
>>
>> Model Translation HABTM Translation:
>>
>> $data = array(
>> 'Translation' => array(
>> 'key' => '213152374'
>> ),
>> 'Language' => array(
>> array(
>> 'id' => '1',
>> 'LanguagesTranslation' => array(
>> 'value' => 'Das ist ein Test'
>> )
>> ),
>> array(
>> 'id' => '2',
>> 'LanguagesTranslation' => array(
>> 'value' => 'This is a test'
>> )
>> )
>> )
>> );
>> $this->Translation->saveAll($data);
>>
>>
>> How i can fill the additional field?
>>
>> I know i can use $this->Translation->LanguagesTranslation->save() bu is 
>> there a better way?
>>
>> Tanks
>> Steffen
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To post to this group, send email to cake...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> cake-php+u...@googlegroups.com .
>> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>>  
>>  
>>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM save Question

2012-09-06 Thread Mohammad Naghavi
Hi Steffen,
what is wrong with
$this->Translation->LanguagesTranslation->save()

that you need a better way?


On Thu, Sep 6, 2012 at 3:25 PM, gloop  wrote:

> Hello,
>
> is there a way to save directly to the joining table? Like the find data?
>
> Model Translation HABTM Translation:
>
> $data = array(
> 'Translation' => array(
> 'key' => '213152374'
> ),
> 'Language' => array(
> array(
> 'id' => '1',
> 'LanguagesTranslation' => array(
> 'value' => 'Das ist ein Test'
> )
> ),
> array(
> 'id' => '2',
> 'LanguagesTranslation' => array(
> 'value' => 'This is a test'
> )
> )
> )
> );
> $this->Translation->saveAll($data);
>
>
> How i can fill the additional field?
>
> I know i can use $this->Translation->LanguagesTranslation->save() bu is
> there a better way?
>
> Tanks
> Steffen
>
>  --
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM with keys pointing to itself.

2012-09-03 Thread Archeious
Sorry I am still a super newbie when it comes to cakephp.  I named it 
courses_courses because that was the two tables that are begin joined.  The 
table is setup like you described (id, course_id, prereq_id).  I am not set 
in stone on any naming convention.  I am just trying to find a quicker way 
to prototype sites.  I ended up doing this site without a framework (doing 
more time researching frameworks then actually working on the site).  I 
would like to know how this could be accomplished.  I can also see it being 
applied to user group that belong to other user groups.

On Tuesday, August 28, 2012 11:42:28 PM UTC-6, Scott Taylor wrote:
>
> I agree that your model and table name is odd, but if it works for you 
> than cool. 
> In an attempt to better understand what you want to do...
> What does your courses_courses table look like?
> I assume it contains the following fields or something like this...
> id, course_id, prereq_id

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM with keys pointing to itself.

2012-08-28 Thread Scott Taylor
I agree that your model and table name is odd, but if it works for you than 
cool. 
In an attempt to better understand what you want to do...
What does your courses_courses table look like?
I assume it contains the following fields or something like this...
id, course_id, prereq_id

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM with keys pointing to itself.

2012-08-28 Thread Archeious
Apparently I am going to just get veiled answers here so I will go 
elsewhere.

On Tuesday, August 28, 2012 8:52:18 AM UTC-6, Dr. Tarique Sani wrote:
>
> Do re-read what I wrote :-) 
>
> Having a model called CoursesCourses is not the way to go... 
>
> Tarique 
>
> On Tue, Aug 28, 2012 at 6:14 PM, Archeious 
> > 
> wrote: 
> > Why what I want to make a model called PrerequisiteCourses?  The courses 
> > themselves are the links.  The way I was trying to do it was with a 
> courses 
> > table and a courses_courses HABTM table.  The problem is foreign keys in 
> > HABTM table would require field_id to point back to the respective 
> columns. 
> > 
> > So you could have a table called recipes that have the fields (id, name) 
> and 
> > a table called ingredients with the fields (id, name) and a third table 
> > called ingredients_recipes with the fields (id, recipe_id, 
> ingredient_id). 
> > Then cakephp will let you setup a HABTM many relations ship. 
> > 
> > In my scenario that two tables are the same table and key off the same 
> > field. 
> > 
> > 
> > 
> > On Tuesday, August 28, 2012 6:25:01 AM UTC-6, Dr. Tarique Sani wrote: 
> >> 
> >> You can create a model called PrerequisiteCourses which uses the 
> >> courses table and then relate Courses habtm PrerequisiteCourses. I 
> >> will leave it to you to figure out how to make the join table ;-) 
> >> 
> >> HTH 
> >> 
> >> Tarique 
> >> 
> >> On Tue, Aug 28, 2012 at 4:35 PM, Archeious  
> >> wrote: 
> >> > So I have a list of courses.  Some of those courses have 
> prerequisites 
> >> > that 
> >> > are also courses.  So I setup a model called Course and a database 
> table 
> >> > called courses.  I have another model called CoursesCourse and a 
> table 
> >> > called courses_courses.  How would I setup it up so view I view a 
> course 
> >> > I 
> >> > get its info and the course it requires (and if possible the courses 
> >> > required by it)? 
> >> > 
> >> > -- 
> >> > You received this message because you are subscribed to the Google 
> >> > Groups 
> >> > "CakePHP" group. 
> >> > To post to this group, send email to cake...@googlegroups.com. 
> >> > To unsubscribe from this group, send email to 
> >> > cake-php+u...@googlegroups.com. 
> >> > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. 
>
> >> > 
> >> > 
> >> 
> >> 
> >> 
> >> -- 
> >> = 
> >> PHP for E-Biz: http://sanisoft.com 
> >> = 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "CakePHP" group. 
> > To post to this group, send email to cake...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > cake-php+u...@googlegroups.com . 
> > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. 
> > 
> > 
>
>
>
> -- 
> = 
> PHP for E-Biz: http://sanisoft.com 
> = 
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM with keys pointing to itself.

2012-08-28 Thread Dr. Tarique Sani
Do re-read what I wrote :-)

Having a model called CoursesCourses is not the way to go...

Tarique

On Tue, Aug 28, 2012 at 6:14 PM, Archeious  wrote:
> Why what I want to make a model called PrerequisiteCourses?  The courses
> themselves are the links.  The way I was trying to do it was with a courses
> table and a courses_courses HABTM table.  The problem is foreign keys in
> HABTM table would require field_id to point back to the respective columns.
>
> So you could have a table called recipes that have the fields (id, name) and
> a table called ingredients with the fields (id, name) and a third table
> called ingredients_recipes with the fields (id, recipe_id, ingredient_id).
> Then cakephp will let you setup a HABTM many relations ship.
>
> In my scenario that two tables are the same table and key off the same
> field.
>
>
>
> On Tuesday, August 28, 2012 6:25:01 AM UTC-6, Dr. Tarique Sani wrote:
>>
>> You can create a model called PrerequisiteCourses which uses the
>> courses table and then relate Courses habtm PrerequisiteCourses. I
>> will leave it to you to figure out how to make the join table ;-)
>>
>> HTH
>>
>> Tarique
>>
>> On Tue, Aug 28, 2012 at 4:35 PM, Archeious 
>> wrote:
>> > So I have a list of courses.  Some of those courses have prerequisites
>> > that
>> > are also courses.  So I setup a model called Course and a database table
>> > called courses.  I have another model called CoursesCourse and a table
>> > called courses_courses.  How would I setup it up so view I view a course
>> > I
>> > get its info and the course it requires (and if possible the courses
>> > required by it)?
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "CakePHP" group.
>> > To post to this group, send email to cake...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > cake-php+u...@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>> >
>> >
>>
>>
>>
>> --
>> =
>> PHP for E-Biz: http://sanisoft.com
>> =
>
> --
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>



-- 
=
PHP for E-Biz: http://sanisoft.com
=

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM with keys pointing to itself.

2012-08-28 Thread Archeious
Why what I want to make a model called PrerequisiteCourses?  The courses 
themselves are the links.  The way I was trying to do it was with a courses 
table and a courses_courses HABTM table.  The problem is foreign keys in 
HABTM table would require field_id to point back to the respective columns.

So you could have a table called recipes that have the fields (id, name) 
and a table called ingredients with the fields (id, name) and a third table 
called ingredients_recipes with the fields (id, recipe_id, ingredient_id).  
Then cakephp will let you setup a HABTM many relations ship.

In my scenario that two tables are the same table and key off the same 
field.


On Tuesday, August 28, 2012 6:25:01 AM UTC-6, Dr. Tarique Sani wrote:
>
> You can create a model called PrerequisiteCourses which uses the 
> courses table and then relate Courses habtm PrerequisiteCourses. I 
> will leave it to you to figure out how to make the join table ;-) 
>
> HTH 
>
> Tarique 
>
> On Tue, Aug 28, 2012 at 4:35 PM, Archeious 
> > 
> wrote: 
> > So I have a list of courses.  Some of those courses have prerequisites 
> that 
> > are also courses.  So I setup a model called Course and a database table 
> > called courses.  I have another model called CoursesCourse and a table 
> > called courses_courses.  How would I setup it up so view I view a course 
> I 
> > get its info and the course it requires (and if possible the courses 
> > required by it)? 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "CakePHP" group. 
> > To post to this group, send email to cake...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > cake-php+u...@googlegroups.com . 
> > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. 
> > 
> > 
>
>
>
> -- 
> = 
> PHP for E-Biz: http://sanisoft.com 
> = 
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM with keys pointing to itself.

2012-08-28 Thread Dr. Tarique Sani
You can create a model called PrerequisiteCourses which uses the
courses table and then relate Courses habtm PrerequisiteCourses. I
will leave it to you to figure out how to make the join table ;-)

HTH

Tarique

On Tue, Aug 28, 2012 at 4:35 PM, Archeious  wrote:
> So I have a list of courses.  Some of those courses have prerequisites that
> are also courses.  So I setup a model called Course and a database table
> called courses.  I have another model called CoursesCourse and a table
> called courses_courses.  How would I setup it up so view I view a course I
> get its info and the course it requires (and if possible the courses
> required by it)?
>
> --
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>



-- 
=
PHP for E-Biz: http://sanisoft.com
=

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM pagination

2012-08-22 Thread Remy Bertot
Hi,

I've tried it myself and it seems to work. But again I am not exactly sure
what you are trying to archive.
Can you be more precise in stating what doesn't work? I might actually just
run into this issue sooner or later if it doesn't work :)

/albums/index/page:2/limit:3 and album.id =
08b54ca4-eb87-11e1-ba1c-080027796c4c returns good results:
array(
(int) 0 => array(
'Gallery' => array(
'id' => '1eb4f5d6-eb87-11e1-ba1c-080027796c4c',
'name' => 'gallery 4'
),
'Album' => array(
(int) 0 => array(
'id' => '08b54ca4-eb87-11e1-ba1c-080027796c4c',
'name' => 'album 1'
)
)
)
)

Here is the sample data I am using
08b54ca4-eb87-11e1-ba1c-080027796c4c album 1
08b54ee8-eb87-11e1-ba1c-080027796c4c album 2
0fba2b5a-eb87-11e1-ba1c-080027796c4c album 3
0fba2cb8-eb87-11e1-ba1c-080027796c4c album 4

1b100d80-eb87-11e1-ba1c-080027796c4c gallery 1
1b100f7e-eb87-11e1-ba1c-080027796c4c gallery 2
1eb4f46e-eb87-11e1-ba1c-080027796c4c gallery 3
1eb4f5d6-eb87-11e1-ba1c-080027796c4c gallery 4

album / gallery
08b54ca4-eb87-11e1-ba1c-080027796c4c 1b100d80-eb87-11e1-ba1c-080027796c4c
08b54ca4-eb87-11e1-ba1c-080027796c4c 1b100f7e-eb87-11e1-ba1c-080027796c4c
08b54ca4-eb87-11e1-ba1c-080027796c4c 1eb4f46e-eb87-11e1-ba1c-080027796c4c
08b54ca4-eb87-11e1-ba1c-080027796c4c 1eb4f5d6-eb87-11e1-ba1c-080027796c4c

Cheers,
Remy




On Tue, Aug 21, 2012 at 6:02 PM, André Luis  wrote:

> Thanks Remy, but it worked in previous version of CakePHP, but now doesnt
> work anymore...
>
> Em terça-feira, 21 de agosto de 2012 09h15min50s UTC-3, remy escreveu:
>>
>> Hi there,
>>
>> Have you looked at this post:
>> http://cakebaker.42dh.com/**2007/10/17/pagination-of-data-**
>> from-a-habtm-relationship/
>>
>> That would translate into this for you, if I'm guessing it right:
>>
>> > // app/controllers/albums_**controller.php
>> class AlbumsController extends AppController {
>> public $paginate = array( 'Gallery' => array('limit' => 4, 'joins' =>
>> array(
>> array(
>> 'table' => 'albums_galleries',
>> 'alias' => 'GalleriesAlbum',
>> 'type' => 'inner',
>> 'conditions'=> array('GalleriesAlbum.gallery_**id =
>> Gallery.id')
>> ),
>> array(
>> 'table' => 'albums',
>> 'alias' => 'Albums',
>> 'type' => 'inner',
>> 'conditions'=> array(
>> 'Albums.id = GalleriesAlbum.album_id',
>> 'Albums.id' => '1'
>> )
>> ;
>>
>> public function index() {
>> $data = $this->paginate('Gallery');
>> debug($data);
>> exit;
>> }
>> }
>>
>> Cheers,
>>
>>
>> On Mon, Aug 20, 2012 at 6:53 PM, André Luis  wrote:
>>
>>> Hi people, i´ve searched for it but I didnt find anything wich really
>>> works.
>>>
>>> I have some Albums, wich the model is Album, and Album HABTM Gallery, so
>>> a gallery can be visible in more than one album. It works fine, BUT i need
>>> to create a pagination for galleries, and all that i´ve found here didnt
>>> work for me. What i need is to use a specific Album to paginate a gallery.
>>> Is that possible? and how can be done?
>>>
>>> Thanks!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To post to this group, send email to cake...@googlegroups.com.
>>> To unsubscribe from this group, send email to cake-php+u...@**
>>> googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/cake-php?hl=en-US
>>> .
>>>
>>>
>>>
>>
>>  --
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM pagination

2012-08-21 Thread André Luis
Thanks Remy, but it worked in previous version of CakePHP, but now doesnt 
work anymore...

Em terça-feira, 21 de agosto de 2012 09h15min50s UTC-3, remy escreveu:
>
> Hi there,
>
> Have you looked at this post:
>
> http://cakebaker.42dh.com/2007/10/17/pagination-of-data-from-a-habtm-relationship/
>
> That would translate into this for you, if I'm guessing it right:
>
>  // app/controllers/albums_controller.php
> class AlbumsController extends AppController {
> public $paginate = array( 'Gallery' => array('limit' => 4, 'joins' => 
> array( 
> array( 
> 'table' => 'albums_galleries', 
> 'alias' => 'GalleriesAlbum', 
> 'type' => 'inner',  
> 'conditions'=> array('GalleriesAlbum.gallery_id = Gallery.id') 
> ), 
> array( 
> 'table' => 'albums', 
> 'alias' => 'Albums', 
> 'type' => 'inner',  
> 'conditions'=> array( 
> 'Albums.id = GalleriesAlbum.album_id', 
> 'Albums.id' => '1' 
> ) 
> ;
>
> public function index() {
> $data = $this->paginate('Gallery');
> debug($data);
> exit;
> } 
> }
>
> Cheers,
>
>
> On Mon, Aug 20, 2012 at 6:53 PM, André Luis 
> > wrote:
>
>> Hi people, i´ve searched for it but I didnt find anything wich really 
>> works.
>>
>> I have some Albums, wich the model is Album, and Album HABTM Gallery, so 
>> a gallery can be visible in more than one album. It works fine, BUT i need 
>> to create a pagination for galleries, and all that i´ve found here didnt 
>> work for me. What i need is to use a specific Album to paginate a gallery. 
>> Is that possible? and how can be done?
>>
>> Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To post to this group, send email to cake...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> cake-php+u...@googlegroups.com .
>> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>>  
>>  
>>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM pagination

2012-08-21 Thread Remy Bertot
Hi there,

Have you looked at this post:
http://cakebaker.42dh.com/2007/10/17/pagination-of-data-from-a-habtm-relationship/

That would translate into this for you, if I'm guessing it right:

 array('limit' => 4, 'joins' =>
array(
array(
'table' => 'albums_galleries',
'alias' => 'GalleriesAlbum',
'type' => 'inner',
'conditions'=> array('GalleriesAlbum.gallery_id = Gallery.id')
),
array(
'table' => 'albums',
'alias' => 'Albums',
'type' => 'inner',
'conditions'=> array(
'Albums.id = GalleriesAlbum.album_id',
'Albums.id' => '1'
)
;

public function index() {
$data = $this->paginate('Gallery');
debug($data);
exit;
}
}

Cheers,


On Mon, Aug 20, 2012 at 6:53 PM, André Luis  wrote:

> Hi people, i´ve searched for it but I didnt find anything wich really
> works.
>
> I have some Albums, wich the model is Album, and Album HABTM Gallery, so a
> gallery can be visible in more than one album. It works fine, BUT i need to
> create a pagination for galleries, and all that i´ve found here didnt work
> for me. What i need is to use a specific Album to paginate a gallery. Is
> that possible? and how can be done?
>
> Thanks!
>
> --
> 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.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: HABTM association: How to populate ONLY the joining table

2012-07-30 Thread Ain Devonshire
i actually have the same issue but how can i put it in view when if i edit 
my user profile? i have Users and UserProfile table

On Sunday, August 8, 2010 10:16:16 PM UTC+8, Mariano C. wrote:
>
> I have books and users table. Both tables have id field as PK, and 
> both have respective Book and User model and controllers. 
>
> There's a third table called books_users, this table have an id field 
> as PK and two FK called user_id and book_id. 
>
> There's a lot of books in the books table, and logged in user can 
> choice to add a book to his collection, to do this is necessary to add 
> a row on books_users table with choosen book's id and logged in user's 
> id. 
>
> Actually I do this through a function add() in the controller 
> BooksUsersController and relative view and model (BookUser). 
> There's a smarter way to do this.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM model fields and Security->disabledFields

2012-02-27 Thread randallj
Thanks! If that is the case, then that will work out just fine for me.

And to address your concern: Yes, the date fields are manipulated by
JavaScript.


On Feb 27, 11:09 am, jeremyharris  wrote:
> You should only need to disable them if they are being manipulated with
> JavaScript.
>
> That said, I've had issues trying anything other than disabling the entire
> HABTM data:
>
> $this->Security->disabledFields = array('BusinessHour');
>
> This is because the way Cake compares the fields does not take into account
> mulitple keys like BusinessHour.0.day, BusinessHour.1.day etc.
>
>
>
>
>
>
>
> On Monday, February 27, 2012 4:41:53 AM UTC-8, randallj wrote:
>
> > See the following code:
>
> >  > // HABTM model fields in view
> > foreach ($daysOfWeek as $k => $day)
> > {
> >    echo $form->input('BusinessHour.'.$k.'.day', array('type' =>
> > 'hidden', 'value' => $k));
> > }
>
> > // Disabling the fields with the Security Component (in controller)?
> > $this->Security->disabledFields = array('BusinessHour.day');
> > ?>
>
> > For HABTM model fields like the ones generated in that foreach loop,
> > do I disable ALL of those fields via Security->disabledFields in the
> > controller as I have indicated?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM model fields and Security->disabledFields

2012-02-27 Thread jeremyharris
You should only need to disable them if they are being manipulated with 
JavaScript.

That said, I've had issues trying anything other than disabling the entire 
HABTM data:

$this->Security->disabledFields = array('BusinessHour');

This is because the way Cake compares the fields does not take into account 
mulitple keys like BusinessHour.0.day, BusinessHour.1.day etc.

On Monday, February 27, 2012 4:41:53 AM UTC-8, randallj wrote:
>
> See the following code: 
>
>  // HABTM model fields in view 
> foreach ($daysOfWeek as $k => $day) 
> { 
>echo $form->input('BusinessHour.'.$k.'.day', array('type' => 
> 'hidden', 'value' => $k)); 
> } 
>
> // Disabling the fields with the Security Component (in controller)? 
> $this->Security->disabledFields = array('BusinessHour.day'); 
> ?> 
>
> For HABTM model fields like the ones generated in that foreach loop, 
> do I disable ALL of those fields via Security->disabledFields in the 
> controller as I have indicated?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM Fixture

2012-01-23 Thread Matteo Landi


On Jan/22, Thiago Silva wrote:
> Hi,
> 
> How can I create a fixture for a HABTM table?

Imagine an app where users are linked together (friendship): you should have
a Model named `UsersUser' and the fixture `UsersUserFixture'. At this point
inside your tests you should be able able to use the fixture using the name
'app.UsersUser'.


Cheers,
Matteo

> I have tried everything but my tests always say the table is missing.
> 
> Thanks,
> Thiago
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> 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
> 

-- 
http://www.matteolandi.net

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM example for CakeDC Search plugin

2011-12-20 Thread designv...@gmail.com
This is what I have currently:

var $filterArgs = array(
array('name' => 'filter', 'type' => 'query', 'method' =>
'orConditions'),
array('name' => 'filter', 'type' => 'subquery', 'method' =>
'findByTags', 'field' => 'NewsPost.id'),
);

public function findByTags($data = array()) {
$this->NewsPostsNewsTag->Behaviors->attach('Containable',
array('autoFields' => false));
$this->NewsPostsNewsTag->Behaviors->attach('Search.Searchable');
$query = $this->NewsPostsNewsTag->getQuery('all', array(
'conditions' => array('NewsTag.name'  => 
$data['filter']),
'fields' => array('news_post_id'),
'contain' => array('NewsTag')
));
return $query;
}

But I'm now getting:

Warning (512): Model "NewsPostsNewsTag" is not associated with model
"NewsTag" [CORE\cake\libs\model\behaviors\containable.php, line 343]

Which is strange, as I wasn't getting that error before?

TIA,

d//t

On Dec 20, 3:13 pm, "designv...@gmail.com" 
wrote:
> Yep! Sure did!
>
> I was fairly sure I had followed everything correctly, but I kept
> getting "Operand should contain 1 column" error?
>
> I looked at debug and the 'tags' portion of the query was returning
> all the fields not just the id's?
>
> I think it's something to do with containable, but I couldn't figure
> it out at all!
>
> d//t
>
> On Dec 20, 2:50 pm, José Lorenzo  wrote:
>
>
>
>
>
>
>
> > Did you read this?
>
> >http://cakedc.com/downloads/view/cakephp_search_plugin

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM example for CakeDC Search plugin

2011-12-20 Thread designv...@gmail.com
Yep! Sure did!

I was fairly sure I had followed everything correctly, but I kept
getting "Operand should contain 1 column" error?

I looked at debug and the 'tags' portion of the query was returning
all the fields not just the id's?

I think it's something to do with containable, but I couldn't figure
it out at all!

d//t



On Dec 20, 2:50 pm, José Lorenzo  wrote:
> Did you read this?
>
> http://cakedc.com/downloads/view/cakephp_search_plugin

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM example for CakeDC Search plugin

2011-12-20 Thread José Lorenzo
Did you read this?

http://cakedc.com/downloads/view/cakephp_search_plugin

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Habtm fields input and view very important plz

2011-09-15 Thread driss
Okay I'll try that and see thanks

On Sep 15, 2:11 am, Jeremy Burns | Class Outfit
 wrote:
> Don't do it as HABTM. Create a model and controller for the joining table and 
> use $belongsTo and $hasMany.
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com
>
> On 14 Sep 2011, at 23:12, driss wrote:
>
>
>
>
>
>
>
> > I have this data structure :
> > Product(Id,name);
> > Market(Id,name);
> > Product HABTM Market ( I mean that i could have products available in
> > many Market or store but the price is not the same for example this
> > product X is available in Market1 and in Market2 but in market1 it's
> > expensive than in Market2) so I figure out that the Join table is the
> > Solution for that situation so I have Added the association HABTM
> > between Product and Market which is for record called
> > Markets_Products  (table) )
> > everything is fine until now I created the tables and everything and I
> > can add Markets where the product exist in the add method for Product
> > all good
> > But I want to add extra field in the association table
> > Markets_products for example price field
> > so Markets_products(Id,market_id,product_id,price) is like that
> > Now my problem is How can I add this field in the add view of  product
> > next to every market name in  the select box ??
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Habtm fields input and view very important plz

2011-09-14 Thread Jeremy Burns | Class Outfit
Don't do it as HABTM. Create a model and controller for the joining table and 
use $belongsTo and $hasMany.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 14 Sep 2011, at 23:12, driss wrote:

> I have this data structure :
> Product(Id,name);
> Market(Id,name);
> Product HABTM Market ( I mean that i could have products available in
> many Market or store but the price is not the same for example this
> product X is available in Market1 and in Market2 but in market1 it's
> expensive than in Market2) so I figure out that the Join table is the
> Solution for that situation so I have Added the association HABTM
> between Product and Market which is for record called
> Markets_Products  (table) )
> everything is fine until now I created the tables and everything and I
> can add Markets where the product exist in the add method for Product
> all good
> But I want to add extra field in the association table
> Markets_products for example price field
> so Markets_products(Id,market_id,product_id,price) is like that
> Now my problem is How can I add this field in the add view of  product
> next to every market name in  the select box ??
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Habtm fields input and view very important plz

2011-09-14 Thread driss
is no one can help me ?
any help is welcome

On Sep 14, 10:12 pm, driss  wrote:
> I have this data structure :
> Product(Id,name);
> Market(Id,name);
> Product HABTM Market ( I mean that i could have products available in
> many Market or store but the price is not the same for example this
> product X is available in Market1 and in Market2 but in market1 it's
> expensive than in Market2) so I figure out that the Join table is the
> Solution for that situation so I have Added the association HABTM
> between Product and Market which is for record called
> Markets_Products  (table) )
> everything is fine until now I created the tables and everything and I
> can add Markets where the product exist in the add method for Product
> all good
> But I want to add extra field in the association table
> Markets_products for example price field
> so Markets_products(Id,market_id,product_id,price) is like that
> Now my problem is How can I add this field in the add view of  product
> next to every market name in  the select box ??

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-09 Thread mr_robot
hi john
thanks for all the help (and the kind encouragement).

i kinda of worked out a solution, posting here for others:

$tag_count = count($artist['Tag']);
$artist = $this->Tags->checkforUpdates($artist);

if (count($artist['Tag'])>$tag_count){

// first save all the tags
foreach($artist['Tag'] as $tag){
$t['Tag'] = $tag;
$t['Artist']['Artist'][0] = $artist['Artist']['id'];
$this->Tag->create();
$this->Tag->save($t);
}

// now del. all the artists assoc. records
$this->ArtistsTag->deleteAll(array('ArtistsTag.artist_id' => $id));

// now save the associations
$i = 0;

foreach($artist['Tag'] as $tag)
 {

$t = $this->Tag->findByName($tag['name']);

// then associate the correct IDs
$this->data[$i]['ArtistsTag']['artist_id']= $id;
$this->data[$i]['ArtistsTag']['tag_id'] = $t['Tag']['id'];

$i++;
 }
// save the assoc.
$saved = $this->ArtistsTag->saveAll($this->data);
}


this seems a very messy and long winded way of doing things. and kinda
of feels like it defeats the object of active record associations. but
it works!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-09 Thread John Andersen
When using that behavior, you must be sure when adding a new Tag to an
Artist, that there already exists at least one other Tag for the
Artist.
The behavior should be modified to just add the new one. That is what
I understand from looking at the source code.

You could also go for the solution, which is mentioned at the bottom
of the page about saving HABTM data in the CakePHP book at:
http://book.cakephp.org/view/1034/Saving-Related-Model-Data-HABTM

Keep up the good work, enjoy,
   John

On Aug 9, 8:27 pm, mr_robot  wrote:
> hi john. yea it's 1.
>
> i have got it working another way with this kind of array:
> $tags = array (
>     0 => array (
>         'Tag' => array (
>              'id' => 123458,
>                         'name' => 'test_tag3',
>             'link' => 'xxx',
>             'source' => 'yyy',
>             'rank' => 2
>         ),
>         'Artist' => array (
>             'Artist' => array (
>                 0 => 7 // this being the artist_id
>             )
>         )
>     ),
>     1 => array (
>         'Tag' => array (
>             'id' => 123456,
>             'name' => 'existing_tag',
>             'link' => 'xxx',
>             'source' => 'yyy',
>             'rank' => 3
>         ),
>         'Artist' => array (
>             'Artist' => array (
>                 0 => 7 // this being the artist_id
>             )
>         )
>     ),
> );
>
> but now it's deleting the already saved associations.
> which leads me to this habtmAdd 
> behavior.http://bakery.cakephp.org/articles/bparise/2007/05/09/add-delete-habt...
> seems like i'm on the right track. but
>
> $this->Artist->habtmAdd('Tag', 1, 123456); //artist_id=1, tag id =
> 123456
>
> does nothing.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-09 Thread mr_robot
hi john. yea it's 1.

i have got it working another way with this kind of array:
$tags = array (
0 => array (
'Tag' => array (
 'id' => 123458,
'name' => 'test_tag3',
'link' => 'xxx',
'source' => 'yyy',
'rank' => 2
),
'Artist' => array (
'Artist' => array (
0 => 7 // this being the artist_id
)
)
),
1 => array (
'Tag' => array (
'id' => 123456,
'name' => 'existing_tag',
'link' => 'xxx',
'source' => 'yyy',
'rank' => 3
),
'Artist' => array (
'Artist' => array (
0 => 7 // this being the artist_id
)
)
),
);

but now it's deleting the already saved associations.
which leads me to this habtmAdd behavior.
http://bakery.cakephp.org/articles/bparise/2007/05/09/add-delete-habtm-behavior
seems like i'm on the right track. but

$this->Artist->habtmAdd('Tag', 1, 123456); //artist_id=1, tag id =
123456

does nothing.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-09 Thread John Andersen
Ok, you have tried that way, but maybe your problem wasn't explained
correctly!
Is your problem one of the following:
1) You want to add tags to an existing artist. The existing artist may
already have some tags and they must be preserved.
2) You want to add a new set of tags to an existing artist, thus
replacing all previous tags added to the artist (this is how HABTM
normally works).
3) You want to do something different from 1 and 2 above.

In 1) you probably have to consider using a HasMany relationship
between Artist and ArtistTag instead of the HABTM between Artist and
Tag.
In 2) you can save more than one tag with each Artist. Just add each
tag to your array and save the Artist.
In 3) more information is needed :)

Enjoy,
   John

On Aug 9, 4:13 pm, mr_robot  wrote:
> so found a solution. sort of. after building some forms and looking at
> the output, i see the format as follows:
>
>     [Tag] => Array
>         (
>             [name] => final2
>             [rank] =>
>         )
>
>     [Artist] => Array
>         (
>             [Artist] => Array
>                 (
>                     [0] => 1903895
>                     [1] => 1903896
>                 )
>
>         )
>
> so have been trying to reconstruct the array, which works:
>
> foreach($artist['Tag'] as $tag){
> $t['Tag'] = $tag;
> $t['Artist']['Artist'][0] = $artist['Artist']['id'];
> //print_r($t);
> //$this->Tag->saveAll($artist['Tag']);
> $this->Tag->create();
> //$this->Tag->save($t, false);
> $this->Tag->save($t);
>
> }
>
> however, it is not saving the tags in the artist_tags table if the
> tags already exist. ie. the validation is stopping the record from
> being saved.
>
> any ideas?
> this also seems to be a very long winded way of doing things. am i
> still missing something?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-09 Thread mr_robot
so found a solution. sort of. after building some forms and looking at
the output, i see the format as follows:

[Tag] => Array
(
[name] => final2
[rank] =>
)

[Artist] => Array
(
[Artist] => Array
(
[0] => 1903895
[1] => 1903896
)

)

so have been trying to reconstruct the array, which works:

foreach($artist['Tag'] as $tag){
$t['Tag'] = $tag;
$t['Artist']['Artist'][0] = $artist['Artist']['id'];
//print_r($t);
//$this->Tag->saveAll($artist['Tag']);
$this->Tag->create();
//$this->Tag->save($t, false);
$this->Tag->save($t);
}


however, it is not saving the tags in the artist_tags table if the
tags already exist. ie. the validation is stopping the record from
being saved.

any ideas?
this also seems to be a very long winded way of doing things. am i
still missing something?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-08 Thread mr_robot
. no luck adding the whole $artist array. it starts to do weird
stuff - adding values from the artist table into the artist_tags
table. very confusing.
will try build a form but this is all very strange - i assumed
relations would be straightforward...?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-08 Thread John Andersen
Yes, I saw that, but the book says you have to do it differently in
order to do it automatically.

You have to refer to the Artist like this:
[code]
$artist['Artist']['id'] = 184287;
[/code]

Observe that you should not just call the save method with the
$artist['Tag'] data only, but the full $artist array.

Else just try to make a form with all the information, execute a save
and take a look at how the resulting array looks like.
Enjoy,
   John

On Aug 8, 9:33 am, mr_robot  wrote:
> hi john
>
> thanks for the answer. but i am doing this:
> $artist['Tag'][1]['artist_id'] = 184287;
>
> regards

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-08 Thread mr_robot
hi john

thanks for the answer. but i am doing this:
$artist['Tag'][1]['artist_id'] = 184287;

regards

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM can't save manually

2011-08-07 Thread John Andersen
You have to populate the related models Id in your array, as it is
explained in the CakePHP book at:
http://book.cakephp.org/view/1034/Saving-Related-Model-Data-HABTM

So for each Tag record, add the related Artist record with just the
primary key of the Artist record.
Enjoy,
   John

On Aug 5, 2:29 pm, mr_robot  wrote:
> hi there
> been pulling my hair out on this one for 2 days.
> i have two simple models.
> artist and tags.
>
> and i have a artists_tags database table with artist_id and tag_id.
>
> artist model
> class Artist extends AppModel {
>
>         var $name = 'Artist';
>         var $hasAndBelongsToMany = array(
>         //      'Tag',
>                 'Tag' => array(
>                         'className' => 'Tag',
>                         'joinTable' => 'artists_tags',
>                         'foreignKey' => 'artist_id',
>                         'associationForeignKey' => 'tag_id',
>                         'unique' => true
> )
>
> }
>
> tags model:
> class Tag extends AppModel {
>
> var $name = 'Tag';
> var $hasAndBelongsToMany = 'Artist';
>
> }
>
>  i can read back values fine. which tells me my associations are
> working correctly.
>
> if i do a print_r($artist) i get:
>
> Array
> (
>     [0] => Array
>         (
>             [id] => 793
>             [name] => ebm
>             [link] =>http://www.bob.com/tag/ebm
>             [source] => 91
>             [rank] =>
>             [ArtistsTag] => Array
>                 (
>                     [id] => 20
>                     [artist_id] => 134426
>                     [tag_id] => 793
>                 )
>
>         )
>
> )
>
> the problem lies in writing the data. i am not using a form, but
> wanting to add data programatically. i fetch a whole lot of data from
> an API then process and insert. this method is working fine for all my
> HAS_MANY associations.
>
> so just trying to manually insert data here fails. it inserts the data
> into the tag model, but never populated the artist_tags table.
>
> if i try something like this:
> $artist = $this->Artist->findById(123456);
> $artist['Tag'][1]['name'] = "rock5";
> $artist['Tag'][1]['link'] = "http://www.last.fm/tag/ebm";;
> $artist['Tag'][1]['artist_id'] = 184287;
> $artist['Tag'][1]['source'] = "Last.fm";
> $artist['Tag'][1]['rank'] = 91;
>
> $this->Artist->Tag->save($artist['Tag'], false);
> or any other variations of save. no luck.
> // none of these work:
> //$this->Artist->Tag->saveAll($artist['Tag']);
> // $this->Tag->save($artist['Tag']);
>
> the sql trace is as follows:
> 45      INSERT INTO `tags` (`name`, `link`, `source`, `rank`) VALUES
> ('rock5', 'http://www.last.fm/tag/ebm', 'Last.fm', 91)
> 46      SELECT LAST_INSERT_ID() AS insertID
> 47      COMMIT
> 48      SELECT COUNT(*) AS `count` FROM `tags` AS `Tag` WHERE `Tag`.`id` =
> 842
> 49      START TRANSACTION
>
> any ideas, help or pointers would be much appreciated.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM again!

2011-07-21 Thread gremlin
What is being said is that you have some conventions you didn't
follow. As a result, you are writing overly-complicated code to handle
what should be automatic within the framework.

Do this:

1) move / rename your users_links table and data to a links_users
table inside mysql.
2) remove completely the model for your join table - the UsersLink
model.
3) define a normal habtm relationship between the User model and the
Link model.
4) read the manual before you start another project - all of this is
clearly explained in many translations.

On Jul 21, 10:45 am, Jeremy Burns | Class Outfit
 wrote:
> I think you are not following the conventions, are making life difficult for 
> yourself and should read the guide.
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com
>
> On 21 Jul 2011, at 17:05, localhost wrote:
>
>
>
>
>
>
>
> > Sorry I didn't understand your reply
>
> > I have defined the relationship
>
> > class UsersLink extends AppModel {
> >    var $belongsTo = array(
> >            'Link' => array(
> >                    'className' => 'Link',
> >                    'foreignKey' => 'link_id',
> >                    'conditions' => '',
> >                    'fields' => '',
> >                    'order' => ''
> >            ),
> >            'User' => array(
> >                    'className' => 'User',
> >                    'foreignKey' => 'user_id',
> >                    'conditions' => '',
> >                    'fields' => '',
> >                    'order' => ''
> >            )
> >    );
>
> > }
>
> > What do you mean by "joining table should be links_users (i.e. the
> > tables are in alphabetical order)"  ?
>
> > On Jul 21, 6:31 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> If you have defined a HABTM relationship your joining table should be 
> >> links_users (i.e. the tables are in alphabetical order).
>
> >> Jeremy Burns
> >> Class Outfit
>
> >>http://www.classoutfit.com
>
> >> On 21 Jul 2011, at 16:26, localhost wrote:
>
> >>> Hi everyone,
>
> >>> I have being trying to solve this for the last 4 hours with no luck.
>
> >>> basically I have the following tables
>
> >>> users
> >>> links
> >>> users_links
>
> >>> Basically I'm trying to get the below query to run using find('all')
> >>> and paginate (I'm running this inside UserController)
>
> >>> SELECT Links.id,Links.Title FROM users,links,users_links WHERE
> >>> user.id=1 AND user.id=users_links.user_id AND
> >>> users_links.link_id=links.id AND users_links.index=1
>
> >>> (see the above sql "users_links.index=1").
>
> >>> how to get this working ?
>
> >>> --
> >>> Our newest site for the community: CakePHP Video 
> >>> Tutorialshttp://tv.cakephp.org
> >>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp 
> >>> others with their CakePHP related questions.
>
> >>> 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
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM again!

2011-07-21 Thread Jeremy Burns | Class Outfit
I think you are not following the conventions, are making life difficult for 
yourself and should read the guide.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 21 Jul 2011, at 17:05, localhost wrote:

> Sorry I didn't understand your reply
> 
> I have defined the relationship
> 
> 
> class UsersLink extends AppModel {
>   var $belongsTo = array(
>   'Link' => array(
>   'className' => 'Link',
>   'foreignKey' => 'link_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   ),
>   'User' => array(
>   'className' => 'User',
>   'foreignKey' => 'user_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   )
>   );
> 
> }
> 
> 
> What do you mean by "joining table should be links_users (i.e. the
> tables are in alphabetical order)"  ?
> 
> 
> On Jul 21, 6:31 pm, Jeremy Burns | Class Outfit
>  wrote:
>> If you have defined a HABTM relationship your joining table should be 
>> links_users (i.e. the tables are in alphabetical order).
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> http://www.classoutfit.com
>> 
>> On 21 Jul 2011, at 16:26, localhost wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Hi everyone,
>> 
>>> I have being trying to solve this for the last 4 hours with no luck.
>> 
>>> basically I have the following tables
>> 
>>> users
>>> links
>>> users_links
>> 
>>> Basically I'm trying to get the below query to run using find('all')
>>> and paginate (I'm running this inside UserController)
>> 
>>> SELECT Links.id,Links.Title FROM users,links,users_links WHERE
>>> user.id=1 AND user.id=users_links.user_id AND
>>> users_links.link_id=links.id AND users_links.index=1
>> 
>>> (see the above sql "users_links.index=1").
>> 
>>> how to get this working ?
>> 
>>> --
>>> Our newest site for the community: CakePHP Video 
>>> Tutorialshttp://tv.cakephp.org
>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
>>> others with their CakePHP related questions.
>> 
>>> 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
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM again!

2011-07-21 Thread localhost
This is one way I found it to be working with find('all') but not with
paginate ( due to the select count)


 $this->User->recursive = -1;
 $options['joins'] = array(
array('table' => 'users_links',
'alias' => 'UsersLink',
'type' => 'inner',
'conditions' => array(
'User.id = UsersLink.user_id',
'UsersLink.inbox = 1'
)
),
array('table' => 'links',
'alias' => 'Link',
'type' => 'inner',
'conditions' => array(
'UsersLink.link_id = Link.id'
)
)
);

$options['fields' ] = array('Link.id', 'Link.title');
$inbox = $this->User->find('all', $options);

What do you think?


On Jul 21, 6:31 pm, Jeremy Burns | Class Outfit
 wrote:
> If you have defined a HABTM relationship your joining table should be 
> links_users (i.e. the tables are in alphabetical order).
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com
>
> On 21 Jul 2011, at 16:26, localhost wrote:
>
>
>
>
>
>
>
> > Hi everyone,
>
> > I have being trying to solve this for the last 4 hours with no luck.
>
> > basically I have the following tables
>
> > users
> > links
> > users_links
>
> > Basically I'm trying to get the below query to run using find('all')
> > and paginate (I'm running this inside UserController)
>
> > SELECT Links.id,Links.Title FROM users,links,users_links WHERE
> > user.id=1 AND user.id=users_links.user_id AND
> > users_links.link_id=links.id AND users_links.index=1
>
> > (see the above sql "users_links.index=1").
>
> > how to get this working ?
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM again!

2011-07-21 Thread localhost
Sorry I didn't understand your reply

I have defined the relationship


class UsersLink extends AppModel {
var $belongsTo = array(
'Link' => array(
'className' => 'Link',
'foreignKey' => 'link_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

}


What do you mean by "joining table should be links_users (i.e. the
tables are in alphabetical order)"  ?


On Jul 21, 6:31 pm, Jeremy Burns | Class Outfit
 wrote:
> If you have defined a HABTM relationship your joining table should be 
> links_users (i.e. the tables are in alphabetical order).
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com
>
> On 21 Jul 2011, at 16:26, localhost wrote:
>
>
>
>
>
>
>
> > Hi everyone,
>
> > I have being trying to solve this for the last 4 hours with no luck.
>
> > basically I have the following tables
>
> > users
> > links
> > users_links
>
> > Basically I'm trying to get the below query to run using find('all')
> > and paginate (I'm running this inside UserController)
>
> > SELECT Links.id,Links.Title FROM users,links,users_links WHERE
> > user.id=1 AND user.id=users_links.user_id AND
> > users_links.link_id=links.id AND users_links.index=1
>
> > (see the above sql "users_links.index=1").
>
> > how to get this working ?
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM again!

2011-07-21 Thread Jeremy Burns | Class Outfit
If you have defined a HABTM relationship your joining table should be 
links_users (i.e. the tables are in alphabetical order).

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 21 Jul 2011, at 16:26, localhost wrote:

> Hi everyone,
> 
> I have being trying to solve this for the last 4 hours with no luck.
> 
> basically I have the following tables
> 
> users
> links
> users_links
> 
> Basically I'm trying to get the below query to run using find('all')
> and paginate (I'm running this inside UserController)
> 
> SELECT Links.id,Links.Title FROM users,links,users_links WHERE
> user.id=1 AND user.id=users_links.user_id AND
> users_links.link_id=links.id AND users_links.index=1
> 
> (see the above sql "users_links.index=1").
> 
> 
> how to get this working ?
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm

2011-06-25 Thread Prabha Vathi
Thanks.
I changed the relation to get the exact query. But, now I am having problem
with "requestAction" which uses tags controller.
I think it is because I have used false in the bind and unbind.

Is it permanently changing the association between models?

On Sat, Jun 25, 2011 at 2:36 PM, Andras Kende  wrote:

>
>
> http://book.cakephp.org/view/1045/Creating-and-Destroying-Associations-on-the-Fly
>
> Removing or adding associations using bind- and unbindModel() only works
> for the *next* find operation only unless the second parameter has been
> set to false. If the second parameter has been set to *false*, the bind
> remains in place for the remainder of the request.
>
> try:
>
> $this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')),
> false);
>
>
>
> this is because paginate first does a count query ...
>
>
> Andras Kende
> http://www.kende.com
>
>
> On Jun 25, 2011, at 3:14 AM, Prabha Vathi wrote:
>
> Hi,
>
> I m not able to get good example for habtm.
> I tried something.
> $this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')));
> $this->Post->bindModel(
> array(
> 'hasOne'=>array(
> 'PostsTag'=>array(
> 'foreignKey'=>false,
> 'type'=>'INNER',
> 'conditions'=>array('PostsTag.post_id = Post.id')
> ),
> 'Tag'=>array(
> 'foreignKey'=>false,
> 'type'=>'INNER',
> 'conditions'=>array(
> 'Tag.id = PostsTag.tag_id'
> )
> )
> )
> )
> );
> $posts = $this->Post->find('all', array('group' => array('Post.id')));
> //working
> Find all works, if i add conditions.
> But if i comment find and add the following line it is not working.
> $this->paginate = array('conditions' => array('Post.status' =>
> 'active','Tag.tag_machine_value' => $name),'limit' => 2,'group' =>
> array('Post.id')); //not working
>
> Any Idea?
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>
>
>  --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>



-- 
-- Prabhavathi

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm

2011-06-25 Thread Andras Kende

http://book.cakephp.org/view/1045/Creating-and-Destroying-Associations-on-the-Fly

Removing or adding associations using bind- and unbindModel() only works for 
the next find operation only unless the second parameter has been set to false. 
If the second parameter has been set to false, the bind remains in place for 
the remainder of the request. 

try:

> $this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')), false);


this is because paginate first does a count query ...


Andras Kende
http://www.kende.com


On Jun 25, 2011, at 3:14 AM, Prabha Vathi wrote:

> Hi,
> 
> I m not able to get good example for habtm.
> I tried something.
> $this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')));
> $this->Post->bindModel(
> array(
> 'hasOne'=>array(
> 'PostsTag'=>array(
> 'foreignKey'=>false,
> 'type'=>'INNER',
> 'conditions'=>array('PostsTag.post_id = Post.id')
> ),
> 'Tag'=>array(
> 'foreignKey'=>false,
> 'type'=>'INNER',
> 'conditions'=>array(
> 'Tag.id = PostsTag.tag_id'
> )
> )
> )
> )
> );
> $posts = $this->Post->find('all', array('group' => array('Post.id'))); 
> //working
> Find all works, if i add conditions.
> But if i comment find and add the following line it is not working. 
> $this->paginate = array('conditions' => array('Post.status' => 
> 'active','Tag.tag_machine_value' => $name),'limit' => 2,'group' => 
> array('Post.id')); //not working
> 
> Any Idea?
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>  
>  
> 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm

2011-06-25 Thread Prabha Vathi
Hi,

I m not able to get good example for habtm.
I tried something.
$this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')));
$this->Post->bindModel(
array(
'hasOne'=>array(
'PostsTag'=>array(
'foreignKey'=>false,
'type'=>'INNER',
'conditions'=>array('PostsTag.post_id = Post.id')
),
'Tag'=>array(
'foreignKey'=>false,
'type'=>'INNER',
'conditions'=>array(
'Tag.id = PostsTag.tag_id'
)
)
)
)
);
$posts = $this->Post->find('all', array('group' => array('Post.id'))); 
//working
Find all works, if i add conditions.
But if i comment find and add the following line it is not working. 
$this->paginate = array('conditions' => array('Post.status' => 
'active','Tag.tag_machine_value' => $name),'limit' => 2,'group' => 
array('Post.id')); //not working

Any Idea?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm

2011-06-24 Thread Master Ram...!
HI

you can solve this problem usign "custom query pagination".

you can search in google you will get many examples.




On Fri, Jun 24, 2011 at 10:02 PM, Prabha Vathi wrote:

> Hi,
>
> In tagscontroller,
> $this->paginate = array('conditions' => array('Post.status' =>
> 'active','Tag.tag_machine_value' => $name),'limit' => 3);
> $posts = $this->paginate('Post');
> $this->set(compact('posts'));
>
> Tag and Post model have hasAndBelongsToMany relation.
>
> I am getting Unknown column 'Tag.tag_machine_value' in 'where clause'
>
> I tried
> $this->Tag->unBindModel(array('hasAndBelongsToMany' => array('Post')));
> $this->Tag->bindModel(array('hasMany' => array('Post')));
>
> But it is still not working
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>



-- 
Master Ram.
Founder n Director of rgPlanets Pvt. Ltd.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm

2011-06-24 Thread Prabha Vathi
Any Help Please?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM pagination

2011-05-06 Thread Dee Johnson
Not sure if you read the question fully or just didnt understand it but I 
have already read ALL of that and frankly it is irrelevant. :)

My issue is not covered anywhere in the cake docs as i have seen.  My 
problem is similar to this guy and I am about to give this a whirl.

http://cakephp.1045679.n5.nabble.com/Paginating-related-results-td3209108.html

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM pagination

2011-05-06 Thread Tilen Majerle
http://book.cakephp.org/view/1231/Pagination read this :)
--
Lep pozdrav, Tilen Majerle
http://majerle.eu



2011/5/6 Dee Johnson 

> Hi guys, I would like to make a
>
> $this->MODEL->find call but would only like to bring back the items related
> to that query and paginate the results.
>
> I tried $this->paginate('Model', ('model.field' => 'value');
>
> and then looped through the results but it looses the pagination on the
> related data...how do I paginate the results?
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM isUnique validation throws error on join model

2011-04-13 Thread francky06l
Well, if you do not use innoDb, atomic is useless anyway ...
'validate' => 'only' should however make it ... Wwhat cake version are
you using ?

On Apr 14, 2:48 am, euromark  wrote:
> 'atomic' => false
> and
> validate => only
> can result in unexpected results^^
> I had to find out the hard way
>
> you cannot simply use if()
> in this case you need some hack like I came up with
>
> if (CommonComponent::logicalAnd($this->Model->saveAll(...,
> array('validate'=>'only'
>
> :)
>
> On 14 Apr., 02:28, francky06l  wrote:
>
> > Do you use saveAll on innoDb tables ? If not, actually set option
> > 'atomic' => false.
> > Try first save with options validate => only and a second saveAll with
> > validate false.
>
> > On Apr 13, 12:06 am, Jeff  wrote:
>
> > > I've got an odd problem.  I have tables/models names and projects with
> > > join table names_projects.  I have an isUnique rule on the name field
> > > in the names table so that I don't have repeat entries.  When I
> > > perform my saveAll with a new name and the validation in place I get
> > > the error:
>
> > > Notice (8): Undefined index: NamesProject [CORE/cake/libs/model/
> > > model.php, line 1701]
>
> > > And a name_id doesn't get passed to my join table insert.  However,
> > > when I remove the isUnique validation on the name model, I don't get
> > > an error and my insert has the last inserted name_id.  With the
> > > validation in place, the validation works, so everything seems like
> > > it's set up fine.  Any ideas on what's going on?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM isUnique validation throws error on join model

2011-04-13 Thread euromark
'atomic' => false
and
validate => only
can result in unexpected results^^
I had to find out the hard way

you cannot simply use if()
in this case you need some hack like I came up with

if (CommonComponent::logicalAnd($this->Model->saveAll(...,
array('validate'=>'only'

:)

On 14 Apr., 02:28, francky06l  wrote:
> Do you use saveAll on innoDb tables ? If not, actually set option
> 'atomic' => false.
> Try first save with options validate => only and a second saveAll with
> validate false.
>
> On Apr 13, 12:06 am, Jeff  wrote:
>
>
>
>
>
>
>
> > I've got an odd problem.  I have tables/models names and projects with
> > join table names_projects.  I have an isUnique rule on the name field
> > in the names table so that I don't have repeat entries.  When I
> > perform my saveAll with a new name and the validation in place I get
> > the error:
>
> > Notice (8): Undefined index: NamesProject [CORE/cake/libs/model/
> > model.php, line 1701]
>
> > And a name_id doesn't get passed to my join table insert.  However,
> > when I remove the isUnique validation on the name model, I don't get
> > an error and my insert has the last inserted name_id.  With the
> > validation in place, the validation works, so everything seems like
> > it's set up fine.  Any ideas on what's going on?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM isUnique validation throws error on join model

2011-04-13 Thread francky06l
Do you use saveAll on innoDb tables ? If not, actually set option
'atomic' => false.
Try first save with options validate => only and a second saveAll with
validate false.


On Apr 13, 12:06 am, Jeff  wrote:
> I've got an odd problem.  I have tables/models names and projects with
> join table names_projects.  I have an isUnique rule on the name field
> in the names table so that I don't have repeat entries.  When I
> perform my saveAll with a new name and the validation in place I get
> the error:
>
> Notice (8): Undefined index: NamesProject [CORE/cake/libs/model/
> model.php, line 1701]
>
> And a name_id doesn't get passed to my join table insert.  However,
> when I remove the isUnique validation on the name model, I don't get
> an error and my insert has the last inserted name_id.  With the
> validation in place, the validation works, so everything seems like
> it's set up fine.  Any ideas on what's going on?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM Multiple Select

2011-04-12 Thread ojonam
Hi,

that seems a bit weird to me at first look, because I am using HABTM 
relations, and edit functions created by the bake tool, and I have my items 
selected, without having had to do anything more. Perhaps if you could paste 
the relevant lines from your edit controller and view, somebody here could 
help?

Cheers,
ojonam

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM Multiple Select

2011-04-11 Thread creat1v1ty
Well that can't be the issue because I'm not doing anything to make
the options selected by default - that is why I posted this question
in the first place. There is no built-in feature in Cake that
automatically selects options based on HABTM relationships.

To confirm, my question is in regards to the "Edit" view for one of my
controllers.

I need to know how to get the options/answers associated to a multiple
select list to be selected by default.

Thanks!

On Apr 11, 9:46 am, ojonam  wrote:
> Hi,
>
> this might in fact be nothing more than a browser issue. Do you have any
> html "debugging" tool like Firebug etc? If so, inspect the html for the
> select box and verify that some of the "options" have value "selected" or
> similar.
> Hope this helps.
>
> Cheers,
> ojonam

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM Multiple Select

2011-04-11 Thread ojonam
Hi,

this might in fact be nothing more than a browser issue. Do you have any 
html "debugging" tool like Firebug etc? If so, inspect the html for the 
select box and verify that some of the "options" have value "selected" or 
similar.
Hope this helps.

Cheers,
ojonam

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM with non-standard fields

2011-04-04 Thread Rob Wilkerson

On Apr 4, 2:17 pm, cricket  wrote:
>
> I suspect the problem is the double underscore. That's jogging my
> memory of something in the Cake libs but I can't quite remember where
> I saw it.
>
> Gotta love those people who insist on "designing" databases in the
> most anally-retentive manner, eh?

Thanks, cricket. This project has been kicking my ass with all of its
non-standardness. Everything is painful even with a framework. Maybe
it has something to do with this ticket:
http://cakephp.lighthouseapp.com/projects/42648/tickets/730-double-underscore-__-in-field-names-messes-up-model-find

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM with non-standard fields

2011-04-04 Thread cricket
On Sun, Apr 3, 2011 at 7:29 PM, Rob Wilkerson  wrote:
> I'm attempting to lay a Cake app over top of a legacy database and I'm
> bumping into a problem with a HABTM relationship. I have a
> TechnologyIncentive that HABTM EnergySource through a join table (no
> model). Here are the specs:
>
> TechnologyIncentive
>  public $name     = 'TechnologyIncentive';
>  public $useTable = 'incentive__incentive_tech';
>  public $primaryKey = 'id';
>
>  public $hasAndBelongsToMany = array(
>    'EnergySource' => array(
>      'className'             => 'EnergySource',
>      'joinTable'             => 'incentive_tech_energy',
>      'foreignKey'            => 'incentive__incentive_tech_id', //
> incentive_tech_energy.incentive__incentive_tech_id
>      'associationForeignKey' => 'incentive_tech_energy_type_id', //
> incentive_tech_energy.incentive_tech_energy_type_id
>    ),
>  );
>
> EnergySource
>  public $name       = 'EnergySource';
>  public $useTable   = 'incentive_tech_energy_type';
>  public $primaryKey = 'incentive_tech_energy_type_id';
>
>  public $hasAndBelongsToMany = array(
>    'TechnologyIncentive' => array(
>      'className'             => 'TechnologyIncentive',
>      'joinTable'             => 'incentive_tech_energy',
>      'foreignKey'            => 'incentive_tech_energy_type_id',
>      'associationForeignKey' => 'incentive__incentive_tech_id',
>    ),
>  );
>
> Even when I try a simple find on TechnologyIncentive like this:
>
>    $es = $this->find( 'all', array(
>      'conditions' => array( 'TechnologyIncentive.id' => 11703 ),
>    ) );
>
> The SQL log shows that the appropriate query was executed and that a
> record was returned, but the result array is empty and I get the
> following notice:
>
> Undefined index: incentive__incentive_tech_id
>
> If I dig through dbo_source.php for a while, I find that the linking
> table (incentive_tech_energy) fields do not include that particular
> field. Every other field comes along for the ride, but not that one. I
> don't know why it's being left out, but that seems to be why the
> result never gets populated.
>
> If anyone knows their way around dbo_source.php and wouldn't mind
> helping, I'd love another set of eyes. Could it be that I'm missing
> something simple?
>

I suspect the problem is the double underscore. That's jogging my
memory of something in the Cake libs but I can't quite remember where
I saw it.

Gotta love those people who insist on "designing" databases in the
most anally-retentive manner, eh?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM COUNT Working but SELECT not adding join table

2011-03-15 Thread cricket
On Tue, Mar 15, 2011 at 12:59 AM, Mike Digital
 wrote:
> I've got two tables and a join table:
> * drink_reviews
> * comments
> * comments_drink_reviews
>
> I am trying to paginate on a specific category and here in lies the
> problem:
>
> 
> $this->Category->DrinkReview->bindModel(array('hasOne' =>
> array('CategoriesDrinkReview')));
> $this->paginate = array(
>  'conditions' => array(
>    'CategoriesDrinkReview.category_id' => $category['Category']['id']
>  ),
>  'limit' => 10
> );
> $reviews = $this->paginate('DrinkReview');
> 
>
> My pagination links (numbers, next, and previous) are all working
> correctly and I see that the initial COUNT in order to create the
> amount of pages is working correctly, but when it gets to the SELECT
> query to get the results, it's saying that it is not performing the
> join to the join table and therefor not selecting that table but still
> applying the "WHERE CategoriesDrinkReview.category_id = #"
>
> This is tremendously frustrating and if anyone can see any glaring,
> immediate issues, I would love to hear it. This join has been a bit of
> a jerk from the get-go, if I may be so honest.
>
> I'm running 1.3.3 but might try and upgrade to 1.3.7 in hopes for
> success.

Not sure where Comment comes into this. Typo?

Try this method:
http://www.littlehart.net/atthekeyboard/2007/12/11/cakephp-pagination-with-a-habtm-relationship

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM: has a related data

2011-03-11 Thread Angelo
Hello,

In fact i found the solution.

First of all:

I paginate in the references controller.

I solved the problem with:

$group = array();
$group[] = 'Lot.id  HAVING COUNT(Watch.id) > 0';

$this->paginate['Lot'] = array(

'limit' => 50,
'contain' => array('Reference', 'Keyword', 'Watch', 'Auction'),
'group' => $group
);

$lots = $this->paginate('Lot', $conditions);

Thanks all for your help!

On 10 mar, 16:39, Sam Bernard  wrote:
> Paginate is a controller function, not a model function- so you can't call
> it on the model.
>
> I'm a little confused as to what you are trying to do- what controller are
> you trying to paginate your "Lot" records from?
>
> Also, have you read the cookbook section on 
> pagination?http://book.cakephp.org/view/1231/Pagination

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM: has a related data

2011-03-10 Thread Sam Bernard
Paginate is a controller function, not a model function- so you can't call 
it on the model.

I'm a little confused as to what you are trying to do- what controller are 
you trying to paginate your "Lot" records from?

Also, have you read the cookbook section on pagination?
http://book.cakephp.org/view/1231/Pagination

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM: has a related data

2011-03-10 Thread Shaz
Have you tried $this->Lot->paginate() ? Just seems like you're
skipping the relationship if you're trying to paginate 'Lot' in
'Watches'?

On Mar 7, 11:44 am, Angelo  wrote:
> Hello,
>
> I have a big problem, i've got the following structure:
>
> var $hasAndBelongsToMany = array(
>
>           'Reference' => array(
>                     'className'              => 'Reference',
>                     'joinTable'              => 'watches',
>                     'foreignKey'             => 'lot_id',
>                     'associationForeignKey'  => 'reference_id',
>                     'unique'                 => true,
>           )
>     );
>
> and
>
> var $hasMany = array(
>         'Watch' => array(
>                 'className'     => 'Watch',
>                 'foreignKey'    => 'lot_id',
>         ),
>
> I would to paginate Lots which has no Reference
>
> I've tried that:
>
> $conditions['Watch.id !='] = '';
> $this->paginate['Lot'] = array(
>             'contain' => array('Watch')
>         );
>
> But it doesn't work.
>
> An important point is maybe that this conditions is a must have only
> if user select a filter.
>
> So maybe i can't really modify the process.
>
> Thanks in advance for our help.
>
> Angelo

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM: has a related data

2011-03-10 Thread Shaz
Have you tried $this->Lot->paginate() ? Just seems like you're
skipping the relationship if you're trying to paginate 'Lot' in
'Watches'?

On Mar 7, 11:44 am, Angelo  wrote:
> Hello,
>
> I have a big problem, i've got the following structure:
>
> var $hasAndBelongsToMany = array(
>
>           'Reference' => array(
>                     'className'              => 'Reference',
>                     'joinTable'              => 'watches',
>                     'foreignKey'             => 'lot_id',
>                     'associationForeignKey'  => 'reference_id',
>                     'unique'                 => true,
>           )
>     );
>
> and
>
> var $hasMany = array(
>         'Watch' => array(
>                 'className'     => 'Watch',
>                 'foreignKey'    => 'lot_id',
>         ),
>
> I would to paginate Lots which has no Reference
>
> I've tried that:
>
> $conditions['Watch.id !='] = '';
> $this->paginate['Lot'] = array(
>             'contain' => array('Watch')
>         );
>
> But it doesn't work.
>
> An important point is maybe that this conditions is a must have only
> if user select a filter.
>
> So maybe i can't really modify the process.
>
> Thanks in advance for our help.
>
> Angelo

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM problem for help

2011-03-06 Thread Ekin Han
Hi Stephen,

Thank you very much for your kindly help.



2011/3/5 Stephen 

> Hi There
>
> From the cookbook:
>
>> *With HABTM, you need to set the ID of the associated model in your data
>> array. We'll build a form that creates a new tag and associates it on the
>> fly with some recipe.* [1]
>>
>
> Try doing User.id not User.username
>
> [1]
> http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM#!/view/1034/Saving-Related-Model-Data-HABTM
>
> On 5 March 2011 07:18, Ekin Han  wrote:
>
>> Hi all,
>>
>> I have such a problem about HABTM.
>>
>> I have 3 tables, users table, bugs table and bugs_users table.
>>
>> The relation ship between users and bugs are just like below:
>>
>> users HABTM bugs
>>
>> bugs HABTM users
>>
>> Now I write a method in Bugs controller which name add() just like below
>>
>> function add(){
>>  if(!empty($this->data)){
>> debug($this->data);
>> die;
>>  $this->Bug->create();
>> if($this->Bug->Save($this->data)){
>>  $this->Session->setFlash(__('Create Successfully', true));
>> $this->redirect(array('action' => 'index'));
>>  } else{
>> $this->Session->setFlash(t('Can Not create bug', true));
>>  }
>> }
>> }
>>
>> And the add.ctp is just like below:
>> Create Bug
>> > echo $form->create('Bug', array('action' => 'add'));
>>  echo $form->input('title');
>> echo $form->input('description');
>>  echo $form->input('User.username');
>> echo $form->end('Submit');
>> ?>
>>
>> I have a problem that when a new bug was add ,the table bugs_uses has
>> nothing new in it.
>>
>> Shall I need to write a record to it myself? That means cake do not
>> automaticly write a record the the relation table?
>>
>>
>>  --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> 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
>>
>
>
>
> --
> Kind Regards
>  Stephen
>
>  http://www.ninjacodermonkey.co.uk
>
>
>  --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM problem for help

2011-03-05 Thread Stephen
Hi There

>From the cookbook:

> *With HABTM, you need to set the ID of the associated model in your data
> array. We'll build a form that creates a new tag and associates it on the
> fly with some recipe.* [1]
>

Try doing User.id not User.username

[1]
http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM#!/view/1034/Saving-Related-Model-Data-HABTM

On 5 March 2011 07:18, Ekin Han  wrote:

> Hi all,
>
> I have such a problem about HABTM.
>
> I have 3 tables, users table, bugs table and bugs_users table.
>
> The relation ship between users and bugs are just like below:
>
> users HABTM bugs
>
> bugs HABTM users
>
> Now I write a method in Bugs controller which name add() just like below
>
> function add(){
>  if(!empty($this->data)){
> debug($this->data);
> die;
>  $this->Bug->create();
> if($this->Bug->Save($this->data)){
>  $this->Session->setFlash(__('Create Successfully', true));
> $this->redirect(array('action' => 'index'));
>  } else{
> $this->Session->setFlash(t('Can Not create bug', true));
>  }
> }
> }
>
> And the add.ctp is just like below:
> Create Bug
>  echo $form->create('Bug', array('action' => 'add'));
>  echo $form->input('title');
> echo $form->input('description');
>  echo $form->input('User.username');
> echo $form->end('Submit');
> ?>
>
> I have a problem that when a new bug was add ,the table bugs_uses has
> nothing new in it.
>
> Shall I need to write a record to it myself? That means cake do not
> automaticly write a record the the relation table?
>
>
>  --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>



-- 
Kind Regards
 Stephen

 http://www.ninjacodermonkey.co.uk

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


RE: HABTM... again

2011-03-02 Thread Krissy Masters
For 1.2 but still applies:

http://marianoiglesias.com.ar/cakephp/modelizing-habtm-join-tables-in-cakeph
p-1-2-with-and-auto-with-models/

or

http://nuts-and-bolts-of-cakephp.com/2008/07/03/notes-on-cakephp-habtm-part-
1-the-basics/

Common mistake is in the name. Filename / classname / singular (plural
mixup).
Also "with" => some_join_table parameter another option.

K


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: RE: HABTM w/ Multiple Select type Field and saveAll() on multiple records.

2011-02-11 Thread OldWest
Thanks for all of the comments. But nothing seems to be resolving this. I 
posted my code for the View, Controller and Model w/ a debug() dump. I am 
able to insert a single record just fine, but when it comes to adding 
multiple records, the index in the array becomes numerical and it needs to 
be a key array with (as noted in the CakePHP manual).

Anyhow, if anyone is feeling brave or knows a solution, please let me know. 
Kinda bummed right now with this : (

Here is the link (see my updated code near the bottom):

http://stackoverflow.com/questions/4950487/cakephp-multiple-entry-fields-w-saveall-habtm-multiple-records-insert-not-savi

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


RE: HABTM w/ Multiple Select type Field and saveAll() on multiple records.

2011-02-10 Thread Krissy Masters
Ok I have done this but it ends up more complicated than first thought.
First thing I found was foreach $i++ was wrong since your loop is made of
the id of the items not a regular count.

I have a simple list of Languages a user can select years with.

Quick example: You must do your find->all( //get all of your Languages); now
edit that list so instead of the standard 0, 1, 2 array you number them
based on the id so you get 6,10,12,15 like the example so when you foreach
you spit out the id.

English [ id 6] <= hidden Language.Language.6.language_id and just make a
Label spit out the name
|dropdown years| <= give year select same array id
Language.Language.6.year_id

Spanish [ id 10]
|dropdown years|

French [ id 12]
|dropdown years|

German [ id 15]
|dropdown years|

When you save you end up with an array of (debug your data before save and
exit(); so you can just keep testing the same thing over ) 
 
Language => array(
Language => array(
[6]=> array(
[year_id] => 2),
[10]=> array(
[year_id] =>),
[12]=> array(
[year_id] => 5),
[15]=> array(
[year_id] => 1),
));

You also have to run this thru a foreach or other way to remove all
Languages that have nothing selected if you allow an option to not be
selected before saving. Then you're left with an array of just selected
options.

That's it. Mine is more indepth than this with validating selects per
options.

One thing I do hate is that a user can make changes when ever you have to
deleteAll previous selections and then save the new array.  A user might
just update English from 2 -5 years to 5 - 10 years keeping the rest the
same but to check each record for changes, additions, deletions, seemed like
way to much.

Im sure there may be other ways to get this done but it works for me.


Good luck  


-Original Message-
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Maurits van der Schee
Sent: Thursday, February 10, 2011 7:15 AM
To: cake-php@googlegroups.com
Subject: Re: HABTM w/ Multiple Select type Field and saveAll() on multiple
records.

Hi,

If you use InnoDB tables in MySQL you can use a transaction:

http://deadlytechnology.com/web-development-tips/jquery-cakephp-tips/

This lets you define a for loop and do multiple save() calls on 
different models and then commit if all went well or rollback on failure.

Regards,

Maurits

On 02/09/2011 11:10 PM, OldWest wrote:
>
> I wanted to know if you have much experience with saveAll() w/ HABTM on
> a multiple select field?
>
> I can get the Zips populated from the plans_zips table (with the below),
> but I cannot get the zips to save in the HABTM plans_zips table..
>
> ...
> *Form->input('"$i".Zip', array(*
> *'type' => 'select',*
> *'multiple' => 'true',*
> *'label' => 'Select the Zips'*
> *));*
> *?>*
> ...
>
> The $i represents the for loop I am using for the adding of multiple
> records.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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


-- 
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help
others with their CakePHP related questions.


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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM w/ Multiple Select type Field and saveAll() on multiple records.

2011-02-10 Thread Maurits van der Schee

Hi,

If you use InnoDB tables in MySQL you can use a transaction:

http://deadlytechnology.com/web-development-tips/jquery-cakephp-tips/

This lets you define a for loop and do multiple save() calls on 
different models and then commit if all went well or rollback on failure.


Regards,

Maurits

On 02/09/2011 11:10 PM, OldWest wrote:


I wanted to know if you have much experience with saveAll() w/ HABTM on
a multiple select field?

I can get the Zips populated from the plans_zips table (with the below),
but I cannot get the zips to save in the HABTM plans_zips table..

...
*Form->input('"$i".Zip', array(*
*'type' => 'select',*
*'multiple' => 'true',*
*'label' => 'Select the Zips'*
*));*
*?>*
...

The $i represents the for loop I am using for the adding of multiple
records.

--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help
others with their CakePHP related questions.


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



--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.



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


Re: HABTM w/ Multiple Select type Field and saveAll() on multiple records.

2011-02-10 Thread ShadowCross
I just saw your other post on this same subject.

per the CakePHP Book (http://book.cakephp.org/view/1031/Saving-Your-
Data):

  saveAll(array $data = null, array $options = array())

  Used to save (a) multiple individual records for a single model or
(b) this record, as well as all associated records

Note the "or".  What you are trying to do is a combination of (a) and
(b) -- saving multiple individual records as well as all associated
records for each or those individual records.  That cannot be
accomplished with a SINGLE saveAll().  Try breaking it down to
iterations of the "(b)" variant.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM w/ Multiple Select type Field and saveAll() on multiple records.

2011-02-09 Thread OldWest
Yes. But I am doing this for multiple record entries. In other words, I am 
adding multiple records at once.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM w/ Multiple Select type Field and saveAll() on multiple records.

2011-02-09 Thread ShadowCross
Have you tried just using:

echo $this->Form->input('Zip');

http://book.cakephp.org/view/1390/Automagic-Form-Elements specifically
provides an example for creating a hasAndBelongsToMany select (just
search for the text "hasAndBelongsToMany" on that page).

On Feb 9, 2:10 pm, OldWest  wrote:
> I wanted to know if you have much experience with saveAll() w/ HABTM on a
> multiple select field?
>
> I can get the Zips populated from the plans_zips table (with the below), but
> I cannot get the zips to save in the HABTM plans_zips table..
>
> ...
> *Form->input('"$i".Zip', array(*
> * 'type'     => 'select',*
> * 'multiple' => 'true',*
> * 'label'    => 'Select the Zips'*
> * ));*
> *?>*
> ...
>
> The $i represents the for loop I am using for the adding of multiple
> records.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm self which joining table

2011-02-08 Thread ibejohn818
First off your naming convention for your table "persons" is
incorrect.

The correct pluralization on "person" is "people".

If you are unsure in the future you can always test our your naming
using the Inflector class.

:-)

On Feb 8, 11:29 pm, John Andersen  wrote:
> Based on your description of your problem, I assume that the following
> requirements should be met:
>
> 1) A person may be related to one or more different person(s).
> 2) A person must be able to group related persons in none, one or more
> relationship groups.
> 3) A person must be able to maintain the list of relationship groups.
>
> Thus there would be a need for the following tables:
>
> a) persons - maintain person related information.
> b) relationships - requirement 1.
> c) groups - requirement 3.
> d) relationship_groups - requirement 2.
>
> The model associations would then become:
> Person habtm Person using Relationship
> Person hasMany Group
> Relationship habtm Group using RelationshipGroup
>
> Hope this helps you on the way, enjoy,
>    John
>
> On 8 Feb., 14:48, Dave  wrote:
>
>
>
> > Persons is the user table...
> > Relations is the relation group and it belongs to person_id
>
> > I then need a table that lists all persons that the RelationOwner has
> > placed into it which consists of person_id(owner) relation_id
> > person_id(person in the relationship)
>
> > CREATE TABLE persons {
> > id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
> > name VARCHAR (20)
>
> > }
>
> > CREATE TABLE relations {
> > id INT UNSIGNED,
> > person_id INT UNSIGNED
> > PRIMARY KEY(id, person_id)
>
> > }
>
> > CREATE TABLE persons_relations_persons {
> > relation_id INT UNSIGNED,
> > persona_id INT UNSIGNED
> > personb_id INT UNSIGNED
> > PRIMARY KEY(relation_id, persona_id, personb_id)
>
> > }
>
> > Thoughts on best practice?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: habtm self which joining table

2011-02-08 Thread John Andersen
Based on your description of your problem, I assume that the following
requirements should be met:

1) A person may be related to one or more different person(s).
2) A person must be able to group related persons in none, one or more
relationship groups.
3) A person must be able to maintain the list of relationship groups.

Thus there would be a need for the following tables:

a) persons - maintain person related information.
b) relationships - requirement 1.
c) groups - requirement 3.
d) relationship_groups - requirement 2.

The model associations would then become:
Person habtm Person using Relationship
Person hasMany Group
Relationship habtm Group using RelationshipGroup

Hope this helps you on the way, enjoy,
   John

On 8 Feb., 14:48, Dave  wrote:
> Persons is the user table...
> Relations is the relation group and it belongs to person_id
>
> I then need a table that lists all persons that the RelationOwner has
> placed into it which consists of person_id(owner) relation_id
> person_id(person in the relationship)
>
> CREATE TABLE persons {
> id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
> name VARCHAR (20)
>
> }
>
> CREATE TABLE relations {
> id INT UNSIGNED,
> person_id INT UNSIGNED
> PRIMARY KEY(id, person_id)
>
> }
>
> CREATE TABLE persons_relations_persons {
> relation_id INT UNSIGNED,
> persona_id INT UNSIGNED
> personb_id INT UNSIGNED
> PRIMARY KEY(relation_id, persona_id, personb_id)
>
> }
>
> Thoughts on best practice?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread Steve
So what does   give you as output ?

On Thu, 2011-01-27 at 14:20 -0800, OldWest wrote:
> And if I try this:
> 
> 
> foreach($plan['State'] as $state): 
>  echo $state[0]['title']; ?>
>  
> 
> 
> Then I get: Fatal error: Cannot use string offset as an array...
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and
> help others with their CakePHP related questions.
>  
>  
> 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


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread OldWest


Thank you for your assistance : ) I solved by doing this:

foreach($plan['Zip'] as $zip): 
echo $zip['title']; ?>


My recursion runs deep, so I did not realize I call the Zip table direct and 
run an innde foreach to parse the Zip array.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread OldWest
And if I try this:

foreach($plan['State'] as $state): 
  echo $state[0]['title']; ?>
 

Then I get: *Fatal error*: Cannot use string offset as an array...

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread OldWest
Let me clarify the relationship a bit more. 

Plan model has state_id field. Each zip belongs to a state.

This inner foreach:
$i = 0;

 

Returns:

Array
(
[0] => Array
(
[id] => 1
[state_id] => 1
[title] => 97378
)

[1] => Array
(
[id] => 2
[state_id] => 1
[title] => 97128
)

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread OldWest
Tried that. Did not work: *Notice* 
(8): 
Undefined index: title

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread Tilen Majerle
Just use $state['title'] inside foreach xD

On Jan 27, 2011 10:59 PM, "OldWest"  wrote:

Hi Ratty,
I am working my way through that, but still cannot solve it. This is what I
have so far:

(inner foreach)

   
   

But I am getting error: *Fatal error*: Cannot use string offset as an array
in...



-- 
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out th...

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread OldWest
Hi Ratty,
I am working my way through that, but still cannot solve it. This is what I 
have so far:

(inner foreach)


   

But I am getting error: *Fatal error*: Cannot use string offset as an array 
in...

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM echo value like standard relationship

2011-01-27 Thread Steve
Try doing 

 and it will show you all the array members.

On Thu, 2011-01-27 at 13:05 -0800, OldWest wrote:
> I might be missing the point on this, but I am trying to echo out a
> HABTM value in my index, and I cannot seem to get the data.
> 
> 
> For example, I can echo these relationships with no issue:
> 
> 
>  
> 
>  
> 
> 
> As you can see from the _id recursive relation on the Plan model.
> 
> 
> Hope my question is clear. Just not sure what to do on this. Can't
> seem to resolve it no matter the combination of vars I try.
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and
> help others with their CakePHP related questions.
>  
>  
> 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


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: HABTM Relations‏ CAKEPHP

2010-12-23 Thread georgeman
It makes a lot more sense to book the description of the book in the
books table, don't you think?

On Dec 23, 12:10 pm, Web Developman  wrote:
> hi
>
> i need save an aditional field in join table, but don't find an
> complete example that showing the correct way to do.
>
> the question is as follows:
>
> I have three tables as follow:
>
> authors (id, name, lastname, nationality)
> books (id, title)
> authors_books(author_id, book_id,description) // Join Table
>
> description is a extra field in the join table that I want to save,
> when save an new author.
>
> for their help I will stay very grateful

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: HABTM question

2010-12-08 Thread cricket
On Wed, Dec 8, 2010 at 5:42 AM, Jens Dittrich  wrote:
> Hello,
>
> I have the following situation in which i need help:
> There are people, roles and lectures, summer_schools and
> presentations.
> People HABTM roles. Depending on their role people are associated to
> lectures or summer_schools or presentations. So I am planning on
> creating more HABTM-tables called lectures_people_roles,
> people_roles_summer_schools and so on.
>
> Is that supported by cakes ORM(bake)? Is ist configurable manually in
> the models or am I asking to much or just making it more complicated
> than necessary?

I think the latter. You could probably use:

Person HABTM Role
Role <-> Lecture
Rol <-> SummerSchool
Role <-> Presentation

I left the other assoc. blank as you haven't described it enough.
Perhaps hasOne/belongsTo? The upshot of it, though, is that you could
do a find on Person and get:

Person
- Role
- [Lecture|SummerSchool|Presentation]

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: HABTM question

2010-12-08 Thread huoxito
I believe people_roles_summer_schools wouldn't be a nice table name
for a cakephp app. I once tried to bake something like that and it
didnt work, instead I used a single name for a table which has many
foreign keys.



On 8 dez, 07:42, Jens Dittrich  wrote:
> Hello,
>
> I have the following situation in which i need help:
> There are people, roles and lectures, summer_schools and
> presentations.
> People HABTM roles. Depending on their role people are associated to
> lectures or summer_schools or presentations. So I am planning on
> creating more HABTM-tables called lectures_people_roles,
> people_roles_summer_schools and so on.
>
> Is that supported by cakes ORM(bake)? Is ist configurable manually in
> the models or am I asking to much or just making it more complicated
> than necessary?
>
> thanks in advance,
> jens

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: HABTM/Linking table structure question

2010-11-01 Thread Dan
I guess I had to use print_r($this->data) instead of the debugger.

On Oct 28, 8:24 am, Dan  wrote:
> On Oct 27, 4:20 pm, Carlos Lavin  wrote:
>
>
>
> > It is "standard". However, CakePHP isn't built to manage multi-column PK's,
> > always single columned
>
> > 2010/10/27 Dan 
>
> > > On Oct 27, 3:07 pm, cricket  wrote:
> > > > On Wed, Oct 27, 2010 at 8:07 AM, Dan  wrote:
> > > > > Structure:
>
> > > > > Projects
> > > > > - project_id
> > > > > - project_name
>
> > > > > Contacts
> > > > > - contact_id
> > > > > - contact_name
>
> > > > > Contacts_Projects
> > > > > - project_id
> > > > > - contact_id
>
> > > > > When reading the Cookbook, in a HABTM setting, I should add an ID
> > > > > field to the Contacts_Projectstable.
>
> > > > That's not a requirement. But, if you find that you need to store
> > > > extra information in the jointable, it's recommended that you then
> > > > add a primary key.
>
> > > > > Wouldn't this field enable the
> > > > > possibility of having duplicates?
>
> > > > UNIQUE(project_id, contact_id);
>
> > > > This creates an index. That's why a PK isn't absolutely necessary.
>
> > > > > Or does the ID field only act as auto number, but the key is still
> > > > > composed of project_id/contact_id?
>
> > > > Sort of. The id column becomes the PK and you'd then have two indexes
> > > > on thetable. If you do add a PK, you should keep the unique index as
> > > > that's what Cake will be using. However, Cake doesn't ever use
> > > > multi-column PKs..
>
> > > Okay, so if mylinkingtablehas a PK comprised of these two fields
> > > (and no ID auto number field) should I remove the primary key and
> > > replace it with an index?
>
> > > My goal is to simply associate contacts to a project, thus each
> > > model's PK. I don't need the ID field in that case right?
>
> > > > that's what Cake will be using. However, Cake doesn't ever use
> > > > multi-column PKs..
>
> > > I always thought that having a multi-column PK was "standard" when
> > > developing a DB?
>
> > > Next, putting those associations to work :)
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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.comFor
> > >  more options, visit this group at
> > >http://groups.google.com/group/cake-php?hl=en
>
> > --
> > -Carlos
>
> Alright, put that to the test. I'm not getting the desired results
> though:
>
> 5       SELECT `Project`.`project_id`, `Project`.`project_name` FROM
> `tsdmgr_projects` AS `Project` WHERE `Project`.`project_id` = 1 LIMIT
> 1               1       1       1
> 6       SELECT `Contact`.`contact_id`, `Contact`.`contact_name`,
> `ContactsProjects`.`project_id`, `ContactsProjects`.`contact_id` FROM
> `tsdmgr_contacts` AS `Contact` JOIN `tsdmgr_contacts_projects` AS
> `ContactsProjects` ON (`ContactsProjects`.`project_id` = 1 AND
> `ContactsProjects`.`contact_id` = `Contact`.`contact_id`)               1     
>   1       0
>
> However, when I print the value of $this->data, I get this:
>
> array(
>         "Project" => array(),
>         "Contact" => array()
> )
>
> Here's the model:
>
> class Project extends AppModel {
>     var $name = 'Project';
>     var $primaryKey = 'project_id';
>
>     var $hasAndBelongsToMany = array(
>                 'Contact' => array(
>                         'className' => 'Contact',
>                         'joinTable' => 'contacts_projects',
>                         'foreignKey' => 'project_id',
>                         'associationForeignKey' => 'contact_id',
>                         'with' => 'ContactsProjects',
>                 ),
>         );
>
> }
>
> Controller bits:
>
> $this->Project->id = $id;
> $this->data = $this->Project->read()
>
> View bits:
>
> Debugger::dump($this->data);
>
> If the two queries are run separately in Toad, they return one record
> as they should (and seems to be indicated).

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: HABTM/Linking table structure question

2010-10-28 Thread Dan
On Oct 27, 4:20 pm, Carlos Lavin  wrote:
> It is "standard". However, CakePHP isn't built to manage multi-column PK's,
> always single columned
>
> 2010/10/27 Dan 
>
>
>
> > On Oct 27, 3:07 pm, cricket  wrote:
> > > On Wed, Oct 27, 2010 at 8:07 AM, Dan  wrote:
> > > > Structure:
>
> > > > Projects
> > > > - project_id
> > > > - project_name
>
> > > > Contacts
> > > > - contact_id
> > > > - contact_name
>
> > > > Contacts_Projects
> > > > - project_id
> > > > - contact_id
>
> > > > When reading the Cookbook, in a HABTM setting, I should add an ID
> > > > field to the Contacts_Projects table.
>
> > > That's not a requirement. But, if you find that you need to store
> > > extra information in the join table, it's recommended that you then
> > > add a primary key.
>
> > > > Wouldn't this field enable the
> > > > possibility of having duplicates?
>
> > > UNIQUE(project_id, contact_id);
>
> > > This creates an index. That's why a PK isn't absolutely necessary.
>
> > > > Or does the ID field only act as auto number, but the key is still
> > > > composed of project_id/contact_id?
>
> > > Sort of. The id column becomes the PK and you'd then have two indexes
> > > on the table. If you do add a PK, you should keep the unique index as
> > > that's what Cake will be using. However, Cake doesn't ever use
> > > multi-column PKs..
>
> > Okay, so if my linking table has a PK comprised of these two fields
> > (and no ID auto number field) should I remove the primary key and
> > replace it with an index?
>
> > My goal is to simply associate contacts to a project, thus each
> > model's PK. I don't need the ID field in that case right?
>
> > > that's what Cake will be using. However, Cake doesn't ever use
> > > multi-column PKs..
>
> > I always thought that having a multi-column PK was "standard" when
> > developing a DB?
>
> > Next, putting those associations to work :)
>
> > 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.comFor
> >  more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en
>
> --
> -Carlos

Alright, put that to the test. I'm not getting the desired results
though:

5   SELECT `Project`.`project_id`, `Project`.`project_name` FROM
`tsdmgr_projects` AS `Project` WHERE `Project`.`project_id` = 1 LIMIT
1   1   1   1
6   SELECT `Contact`.`contact_id`, `Contact`.`contact_name`,
`ContactsProjects`.`project_id`, `ContactsProjects`.`contact_id` FROM
`tsdmgr_contacts` AS `Contact` JOIN `tsdmgr_contacts_projects` AS
`ContactsProjects` ON (`ContactsProjects`.`project_id` = 1 AND
`ContactsProjects`.`contact_id` = `Contact`.`contact_id`)   1   
1   0

However, when I print the value of $this->data, I get this:

array(
"Project" => array(),
"Contact" => array()
)

Here's the model:

class Project extends AppModel {
var $name = 'Project';
var $primaryKey = 'project_id';

var $hasAndBelongsToMany = array(
'Contact' => array(
'className' => 'Contact',
'joinTable' => 'contacts_projects',
'foreignKey' => 'project_id',
'associationForeignKey' => 'contact_id',
'with' => 'ContactsProjects',
),
);
}

Controller bits:

$this->Project->id = $id;
$this->data = $this->Project->read()

View bits:

Debugger::dump($this->data);

If the two queries are run separately in Toad, they return one record
as they should (and seems to be indicated).

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: HABTM/Linking table structure question

2010-10-27 Thread Carlos Lavin
It is "standard". However, CakePHP isn't built to manage multi-column PK's,
always single columned

2010/10/27 Dan 

> On Oct 27, 3:07 pm, cricket  wrote:
> > On Wed, Oct 27, 2010 at 8:07 AM, Dan  wrote:
> > > Structure:
> >
> > > Projects
> > > - project_id
> > > - project_name
> >
> > > Contacts
> > > - contact_id
> > > - contact_name
> >
> > > Contacts_Projects
> > > - project_id
> > > - contact_id
> >
> > > When reading the Cookbook, in a HABTM setting, I should add an ID
> > > field to the Contacts_Projects table.
> >
> > That's not a requirement. But, if you find that you need to store
> > extra information in the join table, it's recommended that you then
> > add a primary key.
> >
> > > Wouldn't this field enable the
> > > possibility of having duplicates?
> >
> > UNIQUE(project_id, contact_id);
> >
> > This creates an index. That's why a PK isn't absolutely necessary.
> >
> > > Or does the ID field only act as auto number, but the key is still
> > > composed of project_id/contact_id?
> >
> > Sort of. The id column becomes the PK and you'd then have two indexes
> > on the table. If you do add a PK, you should keep the unique index as
> > that's what Cake will be using. However, Cake doesn't ever use
> > multi-column PKs..
>
> Okay, so if my linking table has a PK comprised of these two fields
> (and no ID auto number field) should I remove the primary key and
> replace it with an index?
>
> My goal is to simply associate contacts to a project, thus each
> model's PK. I don't need the ID field in that case right?
>
> > that's what Cake will be using. However, Cake doesn't ever use
> > multi-column PKs..
>
> I always thought that having a multi-column PK was "standard" when
> developing a DB?
>
> Next, putting those associations to work :)
>
> 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.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>



-- 
-Carlos

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: HABTM/Linking table structure question

2010-10-27 Thread Dan
On Oct 27, 3:07 pm, cricket  wrote:
> On Wed, Oct 27, 2010 at 8:07 AM, Dan  wrote:
> > Structure:
>
> > Projects
> > - project_id
> > - project_name
>
> > Contacts
> > - contact_id
> > - contact_name
>
> > Contacts_Projects
> > - project_id
> > - contact_id
>
> > When reading the Cookbook, in a HABTM setting, I should add an ID
> > field to the Contacts_Projects table.
>
> That's not a requirement. But, if you find that you need to store
> extra information in the join table, it's recommended that you then
> add a primary key.
>
> > Wouldn't this field enable the
> > possibility of having duplicates?
>
> UNIQUE(project_id, contact_id);
>
> This creates an index. That's why a PK isn't absolutely necessary.
>
> > Or does the ID field only act as auto number, but the key is still
> > composed of project_id/contact_id?
>
> Sort of. The id column becomes the PK and you'd then have two indexes
> on the table. If you do add a PK, you should keep the unique index as
> that's what Cake will be using. However, Cake doesn't ever use
> multi-column PKs..

Okay, so if my linking table has a PK comprised of these two fields
(and no ID auto number field) should I remove the primary key and
replace it with an index?

My goal is to simply associate contacts to a project, thus each
model's PK. I don't need the ID field in that case right?

> that's what Cake will be using. However, Cake doesn't ever use
> multi-column PKs..

I always thought that having a multi-column PK was "standard" when
developing a DB?

Next, putting those associations to work :)

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: HABTM/Linking table structure question

2010-10-27 Thread cricket
On Wed, Oct 27, 2010 at 8:07 AM, Dan  wrote:
> Structure:
>
> Projects
> - project_id
> - project_name
>
> Contacts
> - contact_id
> - contact_name
>
> Contacts_Projects
> - project_id
> - contact_id
>
> When reading the Cookbook, in a HABTM setting, I should add an ID
> field to the Contacts_Projects table.

That's not a requirement. But, if you find that you need to store
extra information in the join table, it's recommended that you then
add a primary key.

> Wouldn't this field enable the
> possibility of having duplicates?

UNIQUE(project_id, contact_id);

This creates an index. That's why a PK isn't absolutely necessary.


> Or does the ID field only act as auto number, but the key is still
> composed of project_id/contact_id?

Sort of. The id column becomes the PK and you'd then have two indexes
on the table. If you do add a PK, you should keep the unique index as
that's what Cake will be using. However, Cake doesn't ever use
multi-column PKs..

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: HABTM with an extra field (saving)

2010-10-09 Thread Jamie
Your HABTM join table needs a primary key, namely "id". That's what
the model code is searching for and not finding.

-Jamie

On Oct 8, 11:31 pm, jwerd  wrote:
> I have an issue where my HABTM save isn't quite working.  I mean it
> is, but it's throwing a few notices to Cake, which I'm concerned
> about:
> Notice (8): Undefined index: id [CORE/cake/libs/model/model.php, line
> 1391]
> Notice (8): Undefined index: id [CORE/cake/libs/model/model.php, line
> 1329]
>
> I know if I turn off debug, these messages won't show but still, it's
> a cause for concern for me.
>
> So I have 3 tables in total...
>
> reviews table:
> id
> title
> (more fields, but irrelevant)
>
> criterias table
> id
> title
> (more fields but irrelevant)
>
> and a joining table, which is HABTM
>
> criteria_review table
> criteria_id
> review_id
> value *
>
> * that's the extra field I'm talking about.
>
> now, in my view code, I copied the way the standard automagic multi-
> select named stuff and came up with this:
>
>                 Form->input('Criteria.Criteria.'.
> $i.'.criteria_id', array('label' => false, 'type'=>'hidden', 'value'=>
> $key)); ?>
>                  $this->Form->input('Criteria.Criteria.'.$i.'.value',
> array('label' => false, 'type'=>'select', 'options'=>array('1'=>'1 out
> of 5','2'=>'2 out of 5','3'=>'3 out of 5','4'=>'4 out of 5','5'=>'5
> out of 5'))); ?>
>
> It saves ok, but it throws those notices up there.  Any ideas on what
> I'm doing wrong or what could be causing that?
>
> Or if you have a better way to deal with EXACTLY what I'm going thru,
> please, by all means, explain your way.
>
> Thanks,
> Jake

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: HABTM

2010-10-05 Thread John L
You made me realize that the problem was caused from the syntax. Thank you.

On Tue, Oct 5, 2010 at 5:57 AM, S Silva  wrote:

> class Book extends AppModel{
>var $hasAndBelongsToMany = array('Author', 'Tag');
>var $belongsTo = 'Publisher';
> }
>
> whats exactly the problem??
>
>
> 2010/10/5 georgeman 
>
> I'm looking for help with associations, specifically HABTM. What if
>> you have more than one HABTM for a model? The parser won't allow it.
>> So what to do? The manual doesn't seem to answer this question or
>> perhaps it does but I didn't see it.
>>
>>
>> This is my setup: If anybody can point our where I am mistaken I would
>> be so grateful
>>
>>
>> I'm setting up a bookshelf application. My models are: Book, Author,
>> Publisher, Tag
>>
>> In my scenario here is the logic:
>>
>> - Book can have one or more Author
>> - Author can have one or more Book
>> - Book can have one Publisher
>> - Publisher can have one or more Book
>> - Book can have one or more Tag
>> - Tag can have one or more Book
>>
>> In my model classes I have set the associations up as follows
>>
>> class Book extends AppModel{
>>var $hasAndBelongsToMany = 'Author';
>>var $belongsTo = 'Publisher';
>> }
>>
>> class Author extends AppModel{
>>var $hasAndBelongsToMany = 'Book';
>> }
>>
>> class Publisher extends AppModel{
>>var $hasMany = 'Book';
>> }
>>
>> class Tag extends AppModel{
>>var $hasAndBelongsToMany = 'Book';
>> }
>>
>> 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.comFor
>>  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.comFor
>  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: HABTM

2010-10-05 Thread S Silva
class Book extends AppModel{
   var $hasAndBelongsToMany = array('Author', 'Tag');
   var $belongsTo = 'Publisher';
}

whats exactly the problem??


2010/10/5 georgeman 

> I'm looking for help with associations, specifically HABTM. What if
> you have more than one HABTM for a model? The parser won't allow it.
> So what to do? The manual doesn't seem to answer this question or
> perhaps it does but I didn't see it.
>
>
> This is my setup: If anybody can point our where I am mistaken I would
> be so grateful
>
>
> I'm setting up a bookshelf application. My models are: Book, Author,
> Publisher, Tag
>
> In my scenario here is the logic:
>
> - Book can have one or more Author
> - Author can have one or more Book
> - Book can have one Publisher
> - Publisher can have one or more Book
> - Book can have one or more Tag
> - Tag can have one or more Book
>
> In my model classes I have set the associations up as follows
>
> class Book extends AppModel{
>var $hasAndBelongsToMany = 'Author';
>var $belongsTo = 'Publisher';
> }
>
> class Author extends AppModel{
>var $hasAndBelongsToMany = 'Book';
> }
>
> class Publisher extends AppModel{
>var $hasMany = 'Book';
> }
>
> class Tag extends AppModel{
>var $hasAndBelongsToMany = 'Book';
> }
>
> 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.comFor
>  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: habtm saving: is my really simple solution fragile? using a model for habtm-table

2010-09-27 Thread Tomfox Wiranata
hey sam, now when u mention it, i think i heard about this and 1.2
tooand i have a primary key field "id"...i can sleep in peace
now...

thank you. i appreciate your help. :)

On 27 Sep., 15:18, Sam  wrote:
> AFAIK, that's actually fine- any time I've used a join table to store
> meta/more than foreign keys I usually end up doing this... The 1.2
> cookbook actually recommended this, but in 1.3 it just says
> "If you plan to add any extra information to this table, it's a good
> idea to add an additional primary key field (by convention 'id') to
> make acting on the table as easy as any other model." (http://
> book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM)
> Which isn't as explicit but definitely implies that it's ok.
>
> On Sep 26, 1:50 pm, Tomfox Wiranata  wrote:
>
> > hi everyone,
>
> > I found this habtm saving tutorial on the net and it wont work for 
> > me:http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior
>
> > it uses both models in the relation and combines them to save or
> > delete data in the habtm-relation. now I had Problems with habtmAdd
> > and habtmDelete. some weird things happen...
>
> > So instead i did it my own way and created a model for my habtm-
> > relation:
>
> > class ProductsCategories extends AppModel
> > {
>
> >         var $name = ProductsCategories';
> >         var $useTable = 'products_categories';
>
> > }
>
> > so everytime a user hits the "save" button to save a relation i do
> > this really simple code using my newly created model
>
> >                                         
> > $this->data['ProductsCategories']['user_id']= $user_id;
> >                                         
> > $this->data['ProductsCategories']['product_id']= $pr_id;
> >                                         
> > $this->data['ProductsCategories']['visible']= "-1";
> >                                         $saved = 
> > $this->ProductsCategories->save($this->data);
>
> > ... instead of the more complex one from the tutorial. and it seems to
> > work. now the big question..
>
> > What is wrong with my code? I am using 1.3. is this not stable?
> > insecure?`will my pc explode? ;)
> > I dont trust my "skills" here.it just seems too easy...
>
> > i am really curios here :) thanks a lot

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


  1   2   3   4   5   6   7   >