Re: HABTM not saving

2009-08-25 Thread delocalizer

Hi Bryan;
Try this:
Array
(
 [Channel]=>Array(
 [id] => 16
 )
 [Area]=>Array(
[Area]=>Array(
   [0] => 14
)
)
That format is the automagic way for cake to save habtm.
Can't remember where I saw it documented but my memory is that the
manual is not clear on this.


On Aug 25, 12:15 am, Bryan Paddock  wrote:
> Hey all,
> Ok I'm pulling my hair out here.
>
> HABTM save/edit/removes are not happening.
>
> I have two models. Channel and Area. The model definitions are configured
> properly (channel: *var $hasAndBelongsToMany = array( 'Area' )* and area: *var
> $hasAndBelongsToMany = array( 'Channel' )* )
>
> I have no clue why this is not working because I am not getting any error
> messages back from cake at all.
>
> I am calling validates() before save() and it validates but it does not
> save.
>
> I am trying to save this array
>
> $data =
>
> Array
> (
>     [Channel] => Array
>         (
>             [id] => 16
>         )
>
>     [Area] => Array
>         (
>             [0] => Array
>                 (
>                     [id] => 14
>                 )
>
>         )
>
> )
>
> I have tried saving this too
>
> Array
> (
>     [Channel] => Array
>         (
>             [id] => 16
>         )
>
>     [Area] => Array
>         (
>             [0] => 14
>         )
>
> )
>
> Is there something I am doing incorrectly? When I push debug level up
> to 3 I can see cake is not even trying to do any of the habtm queries.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



HABTM not saving

2009-08-24 Thread Bryan Paddock
Hey all,
Ok I'm pulling my hair out here.

HABTM save/edit/removes are not happening.

I have two models. Channel and Area. The model definitions are configured
properly (channel: *var $hasAndBelongsToMany = array( 'Area' )* and area: *var
$hasAndBelongsToMany = array( 'Channel' )* )

I have no clue why this is not working because I am not getting any error
messages back from cake at all.

I am calling validates() before save() and it validates but it does not
save.

I am trying to save this array

$data =

Array
(
[Channel] => Array
(
[id] => 16
)

[Area] => Array
(
[0] => Array
(
[id] => 14
)

)

)

I have tried saving this too

Array
(
[Channel] => Array
(
[id] => 16
)

[Area] => Array
(
[0] => 14
)

)

Is there something I am doing incorrectly? When I push debug level up
to 3 I can see cake is not even trying to do any of the habtm queries.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help needed with HABTM not saving data.

2009-06-01 Thread memons

Hi All,
Could some one help me on following:
I have three two tables:
properties : id (auto-increment), title
features : id, title

Since there is many to many relationship between tables, I have third
one:

features_properties: id, feature_id, property_id

Now this is my view: add.ctp.
create('Property');?>


input('title');
echo $form->input('pfor_id');
echo $form->input('ptype_id');
echo $form->input('Feature',array('multiple'=>true));
?>

end('Submit');?>

controller:
add method:
function add() {
if (!empty($this->data)) {
debug($this->data);
$this->Property->create();

if ($this->Property->save($this->data)) {


$this->Session->setFlash(__('The Property has 
been saved', true));
//$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Property could 
not be saved.
Please, try again.', true));
}
}
$features = $this->Property->Feature->find('list');

$this->set(compact('features'));
}

Property Model:
var $hasAndBelongsToMany = array(
'Feature' => array(
'className' => 'Feature',
'joinTable' => 'features_properties',
'foreignKey' => 'property_id',
'associationForeignKey' => 'feature_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
);

Data never gets saved in joint table. Can some one help me on this
please.

--~--~-~--~~~---~--~~
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 not saving multi-select

2007-03-22 Thread stevenoone

If anyone's interested, here's the bug report that was in the tracker
for the array-order problem.

https://trac.cakephp.org/ticket/1819

Hopefully this thread hasn't wasted too much of anyone's time!

sn


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-22 Thread Jon Bennett

On 3/22/07, Jon Bennett <[EMAIL PROTECTED]> wrote:
> > this whole thread is a waste of time, as saving HABTM associations
> > using selectTags is covered in the models section of the manual!
> >
> > go to http://manual.cakephp.org/chapter/models and search for 'Saving
> > hasAndBelongsToMany Relations' (hint, towards the bottom).
>
> actually, on reading, it doesn't provide any controller code, just the
> views, hmm, so, using the view files from the example, I would do
> soemthing like:

sorry, forgot to read the value of the Post, amended:

function edit($post_id)
{
$this->Post->id = $post_id;
// nothign submitted yet
if (empty($this->data))
{
$this->data = $this->Post->read();
// get tag names/ids as key value pairs
$this->set('tags', $this->Post->Tag->generateList());
// render form
$this->render();
}
// data submitted
else
{
// no need to do anything else with the data provided
// you've followed the conventions in the view
if ($this->Post->save($this->data))
{
$this->flash('your post was saved', '/posts');
}
else
{
$this->set('data', $this->data);
$this->validateErrors($this->Post);
$this->render();
}
}
}

hth

jon

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-22 Thread Jon Bennett

> this whole thread is a waste of time, as saving HABTM associations
> using selectTags is covered in the models section of the manual!
>
> go to http://manual.cakephp.org/chapter/models and search for 'Saving
> hasAndBelongsToMany Relations' (hint, towards the bottom).

actually, on reading, it doesn't provide any controller code, just the
views, hmm, so, using the view files from the example, I would do
soemthing like:

function edit($post_id)
{
$this->Post->id = $post_id;
// nothign submitted yet
if (empty($this->data))
{
// get tag names/ids as key value pairs
$this->set('tags', $this->Post->Tag->generateList());
// render form
$this->render();
}
// data submitted
else
{
// no need to do anything else with the data provided
// you've followed the conventions in the view
if ($this->Post->save($this->data))
{
$this->flash('your post was saved', '/posts');
}
else
{
$this->set('data', $this->data);
$this->validateErrors($this->Post);
$this->render();
}
}
}

hope this helps.

jon

>
> hope the tone doesn't appear ranty, I am trying to help (the answers
> are all there).
>
> jon
>
> On 3/22/07, John David Anderson (_psychic_) <[EMAIL PROTECTED]> wrote:
> >
> >
> > On Mar 21, 2007, at 4:41 PM, stevenoone wrote:
> >
> > >
> > > I'm sure for some people the Cake approach makes perfect sense and I
> > > don't doubt that this framework, when used by someone who understands
> > > it well, can dramatically speed development time. Unfortunately
> > > there's people like myself for whom much of this is new, and it's not
> > > unreasonable for us to be frustrated by nuances we haven't yet wrapped
> > > our brains around. Everyone's experience learning this framework is
> > > going to be unique based on their programming background and
> > > familiarity with MVC concepts. It's wonderful that individuals are
> > > volunteering their time to help others get started, but it seems like
> > > sometimes that "help" consists of handwaving half-answers and links to
> > > other semi-related threads.
> > >
> > > Most of us aren't idiots and we wouldn't be posting questions if we
> > > hadn't tried to come up with the answers ourselves. If you don't want
> > > to help in this forum - don't. If you're tired of answering the same
> > > questions, provide good documentation or some well-commented sample
> > > apps and let us pick through the code. This "blame the user for being
> > > confused" attitude in some of these posts and evident in the "essay"
> > > linked above doesn't help anybody.
> >
> > In order for everyone to be happy we're all going to need to try to
> > meet in the middle.
> >
> > For people asking questions: make a better effort to find previously
> > answered questions. Search this group, the Bakery, the Manual, API–
> > and if all else fails–Google. Chances are if you're new, its been
> > asked before. Twice. Its okay to get frustrated with a new system,
> > but try to keep that in check.
> >
> > For the development team: we'll try our best to bulletproof the docs.
> > I try to keep a good handle on the frustrations here and in the IRC
> > channel. Please know we're trying to do what you're asking. Its okay
> > to get frustrated at the lack of resources and constant influx of
> > n00bs, but try to keep that in check.
> >
> > I suppose these both go without saying. Let's just keep plugging on,
> > people.
> >
> > -- John
> >
> > > >
> >
>
>
> --
>
>
> jon bennett
> t: +44 (0) 1225 341 039 w: http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett
>


-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-22 Thread Jon Bennett

this whole thread is a waste of time, as saving HABTM associations
using selectTags is covered in the models section of the manual!

go to http://manual.cakephp.org/chapter/models and search for 'Saving
hasAndBelongsToMany Relations' (hint, towards the bottom).

hope the tone doesn't appear ranty, I am trying to help (the answers
are all there).

jon

On 3/22/07, John David Anderson (_psychic_) <[EMAIL PROTECTED]> wrote:
>
>
> On Mar 21, 2007, at 4:41 PM, stevenoone wrote:
>
> >
> > I'm sure for some people the Cake approach makes perfect sense and I
> > don't doubt that this framework, when used by someone who understands
> > it well, can dramatically speed development time. Unfortunately
> > there's people like myself for whom much of this is new, and it's not
> > unreasonable for us to be frustrated by nuances we haven't yet wrapped
> > our brains around. Everyone's experience learning this framework is
> > going to be unique based on their programming background and
> > familiarity with MVC concepts. It's wonderful that individuals are
> > volunteering their time to help others get started, but it seems like
> > sometimes that "help" consists of handwaving half-answers and links to
> > other semi-related threads.
> >
> > Most of us aren't idiots and we wouldn't be posting questions if we
> > hadn't tried to come up with the answers ourselves. If you don't want
> > to help in this forum - don't. If you're tired of answering the same
> > questions, provide good documentation or some well-commented sample
> > apps and let us pick through the code. This "blame the user for being
> > confused" attitude in some of these posts and evident in the "essay"
> > linked above doesn't help anybody.
>
> In order for everyone to be happy we're all going to need to try to
> meet in the middle.
>
> For people asking questions: make a better effort to find previously
> answered questions. Search this group, the Bakery, the Manual, API–
> and if all else fails–Google. Chances are if you're new, its been
> asked before. Twice. Its okay to get frustrated with a new system,
> but try to keep that in check.
>
> For the development team: we'll try our best to bulletproof the docs.
> I try to keep a good handle on the frustrations here and in the IRC
> channel. Please know we're trying to do what you're asking. Its okay
> to get frustrated at the lack of resources and constant influx of
> n00bs, but try to keep that in check.
>
> I suppose these both go without saying. Let's just keep plugging on,
> people.
>
> -- John
>
> >
>


-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-22 Thread stevenoone

My problem has been resolved, thanks to shepardweb.com for providing a
very detailed tutorial even I could follow. If you're having problems,
visit this link first - you'll save yourself loads of time and
frustration.

http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/

However, this didn't get me all the way to my solution.

I had to apply the "array_keys()" function to filter out the names
from my selected list. If you've implemented the solution from the
link above, and your select list still won't highlight it's default
links selectTag is probably getting an id/name pair where it's only
expecting ids.

$html->selectTag('Computer/Computer',
$computers,array_keys($selected_computers),array('multiple' =>
'multiple'));

A final problem I ran into (and this was a ball-buster) is described
in this post (secret 1).
http://groups.google.com/group/cake-php/browse_thread/thread/b8816db7ff5854bc

My form would submit without error but never bother to update my join
table with the new data. According to the link above, you can't have
your HABTM multi-select as the top element in your form, or you have
to re-order the array before saving in your controller so that the
results array starts with the controller-specific data and then
finishes with the HATBM data. This is a bug in cakePHP & should be
fixed.

Hope this helps somebody - sure would've saved me some time if I had
found it earlier.

Steve

On Mar 21, 3:41 pm, "stevenoone" <[EMAIL PROTECTED]> wrote:
> I'm sure for some people the Cake approach makes perfect sense and I
> don't doubt that this framework, when used by someone who understands
> it well, can dramatically speed development time. Unfortunately
> there's people like myself for whom much of this is new, and it's not
> unreasonable for us to be frustrated by nuances we haven't yet wrapped
> our brains around. Everyone's experience learning this framework is
> going to be unique based on their programming background and
> familiarity with MVC concepts. It's wonderful that individuals are
> volunteering their time to help others get started, but it seems like
> sometimes that "help" consists of handwaving half-answers and links to
> other semi-related threads.
>
> Most of us aren't idiots and we wouldn't be posting questions if we
> hadn't tried to come up with the answers ourselves. If you don't want
> to help in this forum - don't. If you're tired of answering the same
> questions, provide good documentation or some well-commented sample
> apps and let us pick through the code. This "blame the user for being
> confused" attitude in some of these posts and evident in the "essay"
> linked above doesn't help anybody.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-22 Thread John David Anderson (_psychic_)


On Mar 21, 2007, at 4:41 PM, stevenoone wrote:

>
> I'm sure for some people the Cake approach makes perfect sense and I
> don't doubt that this framework, when used by someone who understands
> it well, can dramatically speed development time. Unfortunately
> there's people like myself for whom much of this is new, and it's not
> unreasonable for us to be frustrated by nuances we haven't yet wrapped
> our brains around. Everyone's experience learning this framework is
> going to be unique based on their programming background and
> familiarity with MVC concepts. It's wonderful that individuals are
> volunteering their time to help others get started, but it seems like
> sometimes that "help" consists of handwaving half-answers and links to
> other semi-related threads.
>
> Most of us aren't idiots and we wouldn't be posting questions if we
> hadn't tried to come up with the answers ourselves. If you don't want
> to help in this forum - don't. If you're tired of answering the same
> questions, provide good documentation or some well-commented sample
> apps and let us pick through the code. This "blame the user for being
> confused" attitude in some of these posts and evident in the "essay"
> linked above doesn't help anybody.

In order for everyone to be happy we're all going to need to try to  
meet in the middle.

For people asking questions: make a better effort to find previously  
answered questions. Search this group, the Bakery, the Manual, API– 
and if all else fails–Google. Chances are if you're new, its been  
asked before. Twice. Its okay to get frustrated with a new system,  
but try to keep that in check.

For the development team: we'll try our best to bulletproof the docs.  
I try to keep a good handle on the frustrations here and in the IRC  
channel. Please know we're trying to do what you're asking. Its okay  
to get frustrated at the lack of resources and constant influx of  
n00bs, but try to keep that in check.

I suppose these both go without saying. Let's just keep plugging on,  
people.

-- John

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread stevenoone

I'm sure for some people the Cake approach makes perfect sense and I
don't doubt that this framework, when used by someone who understands
it well, can dramatically speed development time. Unfortunately
there's people like myself for whom much of this is new, and it's not
unreasonable for us to be frustrated by nuances we haven't yet wrapped
our brains around. Everyone's experience learning this framework is
going to be unique based on their programming background and
familiarity with MVC concepts. It's wonderful that individuals are
volunteering their time to help others get started, but it seems like
sometimes that "help" consists of handwaving half-answers and links to
other semi-related threads.

Most of us aren't idiots and we wouldn't be posting questions if we
hadn't tried to come up with the answers ourselves. If you don't want
to help in this forum - don't. If you're tired of answering the same
questions, provide good documentation or some well-commented sample
apps and let us pick through the code. This "blame the user for being
confused" attitude in some of these posts and evident in the "essay"
linked above doesn't help anybody.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread nate

On Mar 21, 4:34 pm, "savagekabbage" <[EMAIL PROTECTED]> wrote:
> stevenoone,
>
> Unfortunatly there's huge lacking of documentation for this framework

And we make up for it by providing specific answers to most questions,
so you don't have to tediously wade through mountains of
documentation ;-)

> which makes the learning curve extremely steep.

Personally I would say 'steep', but are you offering to help remedy
the situation?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread savagekabbage

stevenoone,

Unfortunatly there's huge lacking of documentation for this framework
which makes the learning curve extremely steep.  I'm fairly new to
Cake myself, but it seems like they are going backwards in terms of
documentation.  I was never around for the wiki, but see several links
to resources that may have been very helpful

As for your question, I just throw something like this right above the
selectTag call:

$selected = array();
foreach($params['data']['Location'] AS $info) {
$selected[] = $info['id'];
}

It seems to do the trick for me.  I suppose you could put it in the
controller as well though.

I would also stay away from using manual queries (or why would you be
using a framework?)  Try using a findAll($conditions) instead.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread nate

Oops, that should have been "would not".  I would *not* say 'steep'.

On Mar 21, 5:06 pm, "nate" <[EMAIL PROTECTED]> wrote:
> On Mar 21, 4:34 pm, "savagekabbage" <[EMAIL PROTECTED]> wrote:
>
> > stevenoone,
>
> > Unfortunatly there's huge lacking of documentation for this framework
>
> And we make up for it by providing specific answers to most questions,
> so you don't have to tediously wade through mountains of
> documentation ;-)
>
> > which makes the learning curve extremely steep.
>
> Personally I would say 'steep', but are you offering to help remedy
> the situation?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread nate

On Mar 21, 3:19 pm, "stevenoone" <[EMAIL PROTECTED]> wrote:
> Maybe one of the reasons this HABTM of question is
> getting asked so frequently is that nobody's provided a really good,
> definitive answer of how this works with clear example code for our
> models, views, and controllers.

Having helped manage this mailing list for the better part of two
years now, I can tell you with a fair bit of certainty that this is
most decidedly not the case.  There are a few categories of questions
(HABTM-related questions being chief among them) which people seem to
keep asking no matter how many times they are answered, or how much
relevant, accurate, clear and consice information (and code) is
provided.  I can also tell you with a fair bit of certainty that there
has been quite a bit.

> I realize the onus is on us beginners
> to educate ourselves, and maybe I'm an idiot who can't type five
> letters in a search box, but I'm obviously not the only person who's
> running into problems with this.

Not that the burden isn't on us as a community to provide answers, but
once those answers are provided, it's up to new users to at least put
a little bit of time and effort into trying to find them before asking
again.  Failing to do so is not only disrespectful to those who are
here to help, but you also end up doing a disservice to new users who
come after you by diluting the pool of relevant information.  By
continuing to ask the same questions repeatedly, you actually make it
*harder* to find answers.

I wrote a whole essay on this very topic, which you can find here:
http://cake.insertdesignhere.com/posts/view/11

> Thanks for your help.

As for your actual problem, I'd say the biggest issue is that you're
doing a manual query, which by doing so, you're just creating more
trouble and complexity for yourself than you really need to.  Start by
reading up on models and how to query them here: 
http://manual.cakephp.org/chapter/models.
Pay special attention to the entry on generateList(), then you can
search the list for usage examples with select boxes.

> On Mar 21, 11:44 am, "nate" <[EMAIL PROTECTED]> wrote:
>
> > Hi stevenoone, I'm afraid you'll have to forgive my frustration, as
> > we've had a lot of problems with this lately, but if you abandon this
> > framework out of an inability to enter a search query into the text
> > box in the upper right-hand corner of the page, then I can't say I'll
> > be sorry to see you go.  This exact question has already been answered
> > here more times than I care to count.
>
> >http://groups.google.com/group/cake-php/browse_thread/thread/1bf118d0...
>
> > On Mar 21, 2:03 pm, "stevenoone" <[EMAIL PROTECTED]> wrote:
>
> > > If I can't get this to work I'm going to have to abandon this
> > > framework. I've been developing dynamic websites for 10 years, but
> > > apparently this is just beyond me. I can't seem to get my multi-select
> > > lists to auto-populate correctly or update changes in the database. To
> > > get the auto-populate values I'm trying this in my serials_controller
>
> > > $this->set('mycomps',  $this->Serial->query("SELECT computer_id FROM
> > > computers_serials WHERE serial_id = $this->Serial"));
>
> > > and this in my edit.thtml
>
> > > $html->selectTag('Serial/Computer',$computer_options,
> > > $mycomps,array('multiple' => 'multiple'));
>
> > > it isn't working and I don't know why. If i hard-code "WHERE serial_id
> > > = 1" in the query it returns this array, but I don't see how to fit
> > > that into my selectTag.
>
> > > Array
> > > (
> > > [0] => Array
> > > (
> > > [computers_serials] => Array
> > > (
> > > [computer_id] => 2
> > > )
> > > )
> > > [1] => Array
> > > (
> > > [computers_serials] => Array
> > > (
> > > [computer_id] => 5
> > > )
> > > )
> > > )


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread stevenoone

I appreciate the response and the link and I understand that it's
frustrating when you feel like you're answering the same question over
and over again. Maybe one of the reasons this HABTM of question is
getting asked so frequently is that nobody's provided a really good,
definitive answer of how this works with clear example code for our
models, views, and controllers. I realize the onus is on us beginners
to educate ourselves, and maybe I'm an idiot who can't type five
letters in a search box, but I'm obviously not the only person who's
running into problems with this.

Thanks for your help.

On Mar 21, 11:44 am, "nate" <[EMAIL PROTECTED]> wrote:
> Hi stevenoone, I'm afraid you'll have to forgive my frustration, as
> we've had a lot of problems with this lately, but if you abandon this
> framework out of an inability to enter a search query into the text
> box in the upper right-hand corner of the page, then I can't say I'll
> be sorry to see you go.  This exact question has already been answered
> here more times than I care to count.
>
> http://groups.google.com/group/cake-php/browse_thread/thread/1bf118d0...
>
> On Mar 21, 2:03 pm, "stevenoone" <[EMAIL PROTECTED]> wrote:
>
> > If I can't get this to work I'm going to have to abandon this
> > framework. I've been developing dynamic websites for 10 years, but
> > apparently this is just beyond me. I can't seem to get my multi-select
> > lists to auto-populate correctly or update changes in the database. To
> > get the auto-populate values I'm trying this in my serials_controller
>
> > $this->set('mycomps',  $this->Serial->query("SELECT computer_id FROM
> > computers_serials WHERE serial_id = $this->Serial"));
>
> > and this in my edit.thtml
>
> > $html->selectTag('Serial/Computer',$computer_options,
> > $mycomps,array('multiple' => 'multiple'));
>
> > it isn't working and I don't know why. If i hard-code "WHERE serial_id
> > = 1" in the query it returns this array, but I don't see how to fit
> > that into my selectTag.
>
> > Array
> > (
> > [0] => Array
> > (
> > [computers_serials] => Array
> > (
> > [computer_id] => 2
> > )
> > )
> > [1] => Array
> > (
> > [computers_serials] => Array
> > (
> > [computer_id] => 5
> > )
> > )
> > )


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread nate

Hi stevenoone, I'm afraid you'll have to forgive my frustration, as
we've had a lot of problems with this lately, but if you abandon this
framework out of an inability to enter a search query into the text
box in the upper right-hand corner of the page, then I can't say I'll
be sorry to see you go.  This exact question has already been answered
here more times than I care to count.

http://groups.google.com/group/cake-php/browse_thread/thread/1bf118d0210426e2/94a7689cfeaed6d5?lnk=gst&q=habtm+multi+select&rnum=1#94a7689cfeaed6d5

On Mar 21, 2:03 pm, "stevenoone" <[EMAIL PROTECTED]> wrote:
> If I can't get this to work I'm going to have to abandon this
> framework. I've been developing dynamic websites for 10 years, but
> apparently this is just beyond me. I can't seem to get my multi-select
> lists to auto-populate correctly or update changes in the database. To
> get the auto-populate values I'm trying this in my serials_controller
>
> $this->set('mycomps',  $this->Serial->query("SELECT computer_id FROM
> computers_serials WHERE serial_id = $this->Serial"));
>
> and this in my edit.thtml
>
> $html->selectTag('Serial/Computer',$computer_options,
> $mycomps,array('multiple' => 'multiple'));
>
> it isn't working and I don't know why. If i hard-code "WHERE serial_id
> = 1" in the query it returns this array, but I don't see how to fit
> that into my selectTag.
>
> Array
> (
> [0] => Array
> (
> [computers_serials] => Array
> (
> [computer_id] => 2
> )
> )
> [1] => Array
> (
> [computers_serials] => Array
> (
> [computer_id] => 5
> )
> )
> )


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread stevenoone

If I can't get this to work I'm going to have to abandon this
framework. I've been developing dynamic websites for 10 years, but
apparently this is just beyond me. I can't seem to get my multi-select
lists to auto-populate correctly or update changes in the database. To
get the auto-populate values I'm trying this in my serials_controller

$this->set('mycomps',  $this->Serial->query("SELECT computer_id FROM
computers_serials WHERE serial_id = $this->Serial"));

and this in my edit.thtml

$html->selectTag('Serial/Computer',$computer_options,
$mycomps,array('multiple' => 'multiple'));

it isn't working and I don't know why. If i hard-code "WHERE serial_id
= 1" in the query it returns this array, but I don't see how to fit
that into my selectTag.

Array
(
[0] => Array
(
[computers_serials] => Array
(
[computer_id] => 2
)
)
[1] => Array
(
[computers_serials] => Array
(
[computer_id] => 5
)
)
)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread stevenoone

Bumping up the debug level, it looks like it's running the correct
join:

SELECT `Computer`.`id`, `Computer`.`employee_id`,
`Computer`.`pc_model_id`, `Computer`.`protection_plan`,
`Computer`.`asset_tag_no`, `Computer`.`profiler_dump` FROM `computers`
AS `Computer` JOIN `computers_serials` ON
`computers_serials`.`serial_id` = '3' AND
`computers_serials`.`computer_id` = `Computer`.`id` WHERE 1 = 1

but I'm not asking for the results correctly. Here's what I'm using in
edit.thtml

$html->selectTag
('Computer/Serial',
$computers,
$html->tagValue('Serials/computer_id'),
array('multiple' => 'multiple'))


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-21 Thread stevenoone

Bumping up the debug level, it looks like it's running the correct
join:

SELECT `Computer`.`id`, `Computer`.`employee_id`,
`Computer`.`pc_model_id`, `Computer`.`protection_plan`,
`Computer`.`asset_tag_no`, `Computer`.`profiler_dump` FROM `computers`
AS `Computer` JOIN `computers_serials` ON
`computers_serials`.`serial_id` = '3' AND
`computers_serials`.`computer_id` = `Computer`.`id` WHERE 1 = 1

but I'm not asking for the results correctly. Here's what I'm using in
edit.thtml

$html->selectTag
('Computer/Serial',
$computers,
$html->tagValue('Serials/computer_id'),
array('multiple' => 'multiple'))


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM not saving multi-select

2007-03-20 Thread stevenoone

I just noticed I don't have foreign keys set up on my
computers_serials table - is this required for cakePHP to understand
HABTM relationships?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



HABTM not saving multi-select

2007-03-20 Thread stevenoone

I'm trying to set up a relationship where a serial number can be used
on multiple computers and computers can have multiple serial numbers.
I have a computers_serials table with computer_id and serial_id
columns. In my Computers model I have "var $hasAndBelongsToMany =
'Serial'; " and in my Serials model I have "var $hasAndBelongsToMany =
'Computer';". In my Serials controller I'm getting a list of computers
via "$this->set('computers',  $this->Serial->Computer-
>generateList());" and populating a multi-select in my serials
\edit.thtml with "$html->selectTag('Serial/Computer', $computers,
null, array('multiple' => 'multiple'))".

My edit view doesn't read the initial selection state of the multi-
select from computers_serials or insert data back into that same table
on save. It also doesn't throw an error. I know I'm missing something
but I can't figure out what. I've seen a lot of discussion about this
in the archives, and I've come to understand that if implemented
correctly, Cake should be able to manage these relationships fairly
automatically. I'd appreciate any help I can get.

sn


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---