Hi Stephen,
Thank you very much for your kindly help.
2011/3/5 Stephen step...@ninjacodermonkey.co.uk
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
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(){
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]
Hi, everyone,
I am a newbie to cakephp, I am learning the HABTM, and try to see the
post tag example working with the $scaffold.
I have added the $hasAndBelongsToMany in both model files, but when I
open the /blog/posts/add, I can never see the tags with the
scaffolding. So frustrating...
I
How about using WITH in the Judge-Model? Is this a good way to do
it?
class Judges extends AppModel
{
var $name = Judge;
var $hasAndBelongsToMany = array(MediaSegments = array(with =
JudgesMediaSegments));
}
On 15 Apr., 02:37, Bryan Paddock bryanpadd...@gmail.com wrote:
Ah! Thank you!
Hey all,
Going a bit crazy here I think I need a break from this. Anyways,
I have the following tables + relationships
Judges
MediaSegments (a category that the judge is selected to judge)
JudgesMediaSegments (contains judge_id and media_segment_id)
How would I find all the judges that belong
Are you using Containable behaviour? You should be!
Try this...(typed without testing - so go easy on me if it's wrong!)...
From the MediaSegment controller:
$this-MediaSegment-find(
'all',
array(
'contain' = array(
'Judge'
Ah! Thank you!
After a while of tinkering with your code I realised I had the $actsAs in
the controller and not the model :(
Works like a charm. I've modified all of my code now to use containable
behaviour. Gone with recursive = -1.
On Wed, Apr 14, 2010 at 3:45 PM, Jeremy Burns
Contain does do extra queries and then merges arrays back together.
It's great for certain situations and not so great for others. I
particularly like to use it when viewing records and associated data,
but I'm not so keen within indexes/lists of data.
Bind and unbind allow you to force joins
Try using contain and doing a
$result = $this-Playlist-find('first', array(
'conditions'=array('Playlist.id'=$id),
'contain'=array('Song'=array('Artist','Album'))
));
Then do an echo debug($result); to see what it's fetched and how the
array is structured.
I beware of using contain, 'cause I don't understand how it works yet.
I know that at least some times it runs multiple queries to achieve
it's goal. Thanks for the tip though.
After fighting with that thing for some time I did some unbind/bind
models. And got the result with single query at
Let's say I've got table Playlists and table Songs (this one has it's
own associations with Artists, Albums, etc.) that obvously got HABTM
association (all tables are named properly, according to Cake
conventions).
Now the question (probably it's very dumb, sorry :) I got HABTM
association
I will rephrase a bit.
As I said I have table Playlists and table Songs (this one has it's
own associations with Artists, Albums tables, etc.) that obviously got
HABTM
association (all tables are named properly, according to Cake
conventions).
Now, how do I retrieve all songs, with all the
hi peoples,
i have two models is cakephp:
class Pessoa extends AppModel {
var $name = 'Pessoa';
var $primaryKey = 'codigo';
var $hasAndBelongsToMany = array(
'Areainteresse' =
array(
'className'= 'Areainteresse',
What does the find() code look like?
It's possible that the problem is with your unconventional column
names. It might work better if you use, eg. 'areainteresse_pessoa' for
the join table and 'pessoa_id' for the key.
Or it might be something else.
On Fri, Sep 25, 2009 at 11:30 AM, Wladiston
unfortunately not always possible.
because the database already exists. I am only deploying the system in PHP
(currently Delphi). and the base is in Firebird.
I had problems with the Auth component because of the Firebird, I believe
the problem is the integration of the cake with the firebird.
I
Hello,
I have a problem with a couple of models that share a HABTM
relationship. I've tried two different approaches, but none provide
the desired result. Here are they both, I hope you can help me to fix
either of them to get the array I need.
I'm using the good old
Post hasAndBelongsToMany
I have standard users table. Every user can have many accounts
(account is a group of permissions, like a role) and every account can
be linked to many users. Relation is HABTM as you can see. When I
call:
$accounts=$this-User-find('first', array('conditions' = array
('User.user_id' = 1)));
i
Here's my problem: If the foreign key in the HABTM join table isn't
unique and could therefore return multiple matching records, all the
records should be part of the returned dataset. The way it works now,
only the first record is returned and the others are skipped.
Simple example:
Model
it is clear now
thanks for your help :-)
--
View this message in context:
http://n2.nabble.com/HABTM-problem-tp2363919p2367984.html
Sent from the CakePHP mailing list archive at Nabble.com.
--~--~-~--~~~---~--~~
You received this message because you
the name and family name such that one tag_id is mapped
to one name to solve this problem. But I just wanna know whether it is
possible for one key to be mapped with more than one values.
Thanks very much for your help.:-)
kit
--
View this message in context:
http://n2.nabble.com/HABTM-problem
here my question comes:
as more ppl are added in the tags table i added another column
tag_id namefamilyname
--
1 DavidBeckham
2 John Terry
3 Christano Ronaldo
4
If I comment out other habtm relationships, leaving only
var $hasAndBelongsToMany = array(
'HasAsFriend' = array(
'className' = 'User',
'joinTable' = 'friends',
'foreignKey' = 'user_id',
I added some logging just to make sure the relationships are unbound:
$this-User-unbindAll(array('hasAndBelongsToMany' =
array('HasAsFriend')));
$this-log(current habtm: . print_r($this-User-
hasAndBelongsToMany, true));
The error log reads:
2008-05-08 17:03:49 Error:
For anybody who's following this thread, or had the same problem, or
dived in during a google:
This seems like a bug mentioned at https://trac.cakephp.org/ticket/4558
After adding a unset($newValues) as the ticket mentions the problem
goes away.
Thanks all!
On May 8, 5:08 pm, largon [EMAIL
Hi,
I'm on a project that users can add other users as friends, families,
or block them.
So I've set up some habtm behaviors for that. The tables (friends,
families, blocks) look
very similar, all with (user_id, friend_id) or (user_id, family_id) as
keys.
But when I save a data, like calling:
I was just having the same problem, used your method and it's working
fine now.
On Mar 30, 9:36 pm, ste.ve [EMAIL PROTECTED] wrote:
To visualize it better, these are my example Model definitions
WORKS:
class Tag extends AppModel {
var $hasAndBelongsToMany = array(
You just need to change the alias :
class Tag extends AppModel {
var $hasAndBelongsToMany = array(
'RelatedTag' = array('className' = 'Tag')
);
}
In your resultset the `Tag` key will now refer to the main tag and
the `RelatedTag` will contain the related tags. Of course you can
change
I have a Model (Model_1) which is related to itself by a second
model (Model_2) by a HABTM relation. Model_2 uses a custom table
(var $usetable = model_1)
The problem: When I make a find call on Model_1, it returns correctly
the row for itself, and the correct number of rows for Model_2, BUT
all
To visualize it better, these are my example Model definitions
WORKS:
class Tag extends AppModel {
var $hasAndBelongsToMany = array(
'Tag2' = array(
'foreignKey' =
'tag_id',
Nvm, fixed. Was searching the google groups for the wrong term.
On Nov 21, 12:55 pm, Action [EMAIL PROTECTED] wrote:
I need to set up a HABTM association between two tables: users and
teams.
The problem I'm having is that the primary key in the users table is
called user_id, not id. (I am
I need to set up a HABTM association between two tables: users and
teams.
The problem I'm having is that the primary key in the users table is
called user_id, not id. (I am not allowed to change this).
How do I set up my join table and association so it associates Team.id
with User.user_id, not
if you did check the manual, in 'models' chapter, you find about
model variables:
http://manual.cakephp.org/chapter/models
$primaryKey
If this model relates to a database table, and the table's primary
key is not named 'id', use this variable to tell Cake the name of the
primary key.
On Nov 20, 7:24 am, Dianne van Dulken [EMAIL PROTECTED] wrote:
Thanks for that Yolabingo.
It turned out I was making it all a bit too difficult for myself, so
I'll put the solution here in case anyone else is having the same
problem.
Same as above except what I had to do before save is
Thanks for that Yolabingo.
It turned out I was making it all a bit too difficult for myself, so
I'll put the solution here in case anyone else is having the same
problem.
Same as above except what I had to do before save is to force the
['articles']['articles'] values to be my array. So
On Nov 12, 5:35 pm, Dianne van Dulken [EMAIL PROTECTED] wrote:
function beforeSave() {
$articles = explode(,, $_POST[data]['Teaser'][articles]);
$this-Teaser-habtmAdd('Article', $this-data['Teaser']['id'],
$articles);
return parent::beforeSave();
//return
hi, its ahsan.
I am new to cakephp , but old to php :-)
In the last section of the manual 's model description .. its described
about the details of HABTM association between posts and tags..
the scenario presented there in last example is to associate a newly
created post with a relevant tags,
Generally if you're getting undefined variable it's because you
haven't set the variable for the view to access.
It depends what's on line 31 in your add.thtml file, but I'm guessing
it's:
$html-selectTag('Product/Product',$products)
In which case you just need to set the $products variable in
38 matches
Mail list logo