Re: transaction

2008-07-13 Thread .
i am using mysql

On Sun, Jul 13, 2008 at 9:06 AM, Marcin Domanski <[EMAIL PROTECTED]> wrote:

>
> Maybe your database doesnt support transactions ?
> --
> Marcin Domanski
> http://kabturek.info
>
>
> On Sun, Jul 13, 2008 at 10:39 AM, . <[EMAIL PROTECTED]> wrote:
> > I have the following transaction, but even on errors, it does not
> rollback.
> > Why?
> >
> > $this->List->begin();
> > $this->List->create();
> > $this->data['List']['id']=1;
> > ... do so more set up
> > $this->List->save($this->data)
> >
> > if (...is okay...)
> > $this->List->commit();
> > else
> > $this->List->rollback();
> >
> > do i have the right syntax? I manually force the $this->List->rollback()
> to
> > execute, but  I still see the record in the database. Why?
> >
> > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



JavaScript onClick (next and back) call $Id... Can you help me please....

2008-07-13 Thread randalle2

Hi guys,
Can anybody help with javascript next and back buttons...

My code goes likes this...


 Tab 1
 Tab 2
 Tab 3

dynamic content will fall here...

Here's my problem...
I want to put a next and back buttons..like this

Next
Back

When i click it will call the ($id)...

Help me please... Im a newbie...
by the way.. im using prototype library...

thanks a lot


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: CakePHP and widgets

2008-07-13 Thread Dr. Tarique Sani
On Mon, Jul 14, 2008 at 2:31 AM, Steve <[EMAIL PROTECTED]> wrote:

>
> I was wondering what the best approach for creating widgets (type of
> elements) with Cake. What I mean by widgets is basically elements that
> pull data from something that may not relate to the current controller/
> action the user is in.


Andy Dawson's mini controllers still work the best for me - despite the name
it really is a combination of Components and Elements


Tarique

-- 
=
Cheesecake-Photoblog: http://cheesecake-photoblog.org
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $this->Auth->user not refreshing after edit

2008-07-13 Thread Jonathan Snook

On 7/13/08, RichardAtHome <[EMAIL PROTECTED]> wrote:
>  It looks like the Users model is only being read once at login and the
>  details stored in a session (not checked the cake code, but that would
>  match the behaviour I am experiencing).
>
>  Basically, the edit is working (ie, database gets updated), but the
>  $this->Auth->user() isn't.

I contend that this is the preferred behaviour. Refreshing the user
object stored in the session is unnecessary on 99% of the page views
(I suspect most users don't edit their profiles on a regular basis).

I suspect that it's just a simple storing of the current user in the
session (in Session->read('User')) but it'd be nice to have an
Auth->refreshSession() method that would refresh the current user in
the session. Maybe submit a ticket for that...

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: database convention

2008-07-13 Thread onefootswill

Thanks. I definitely want to go down the 'less cumbersome' road.

On Jul 14, 1:43 am, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
> > Absolute noob here. I have a question about cakePhp database
> > convention. From my understanding of the manual, every table requires
> > a single attribute primary key.
>
> > So, in a table where you might normally have a composite key with two
> > attributes, you should add an 'artificial identifier' as a single-
> > attribute primary key for each tuple, and use that rather than the
> > composite key.
>
> > Firstly, have I got that right?
>
> Yes, you got that right. For some people it sounds dirty but it
> simplifies things a lot.
>
> > Secondly, do people tend to use AUTO INCREMENT a lot to implement such
> > functionality in their databases?
>
> And yes again for the same reason. But it's no mandatory, you can set
> the keys on your own and make your development more cumbersome.
>
> Also UUIDS are supported (and are great) as primary keys, you can set
> the primary key to be char(36) and cake will take care of 
> it:http://book.cakephp.org/complete/3/the-manual
>
>
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: CakePHP and widgets

2008-07-13 Thread the_woodsman

An alternative to excessive use of requestAction is to put as much in
the models as you can, and carefully load models in your controllers
to pass stuff into views.

For your example, you could:
 * give all models a random() and recent() method
 * Create a WithSnippets controller, and subclass this for all
controllers that need these snippets
 * In WithSnippets, pass all these recents and randoms into the view
 * In the layout (or in helpers), check for the presence of these, and
render them if they've been set

This might not be the most elegant solution (instead of a WithSnippets
controller you could perhaps use Components - it's late here, gimme a
break! ) but you get the idea - put your code reuse in the models and
things you can share between controllers, so you don't have to use
requestAction.
This saves you from calling the dispatcher over and over (I think).


On Jul 13, 10:35 pm, "Mark (Germany)" <[EMAIL PROTECTED]>
wrote:
> thats really a good question
> i would like to know that mysefl
>
> i found out though, that requesting might not be the best...
> the database querys went up by 30%
> especially if you get config details and session infos from the
> Database,
> they will be requested as often as you use this "requestAction" thing
>
> makes sense, because it includes these widgets as n external source
> reforcing sessionstart etc.
>
> as soon as i found out, i started to work with controllers, which get
> there information
> from the models
>
> dont know if theres a better solution
> but i dont wanna have 24 querys where 12 are possibly
>
> On 13 Jul., 23:01, Steve <[EMAIL PROTECTED]> wrote:
>
> > Hey,
>
> > I was wondering what the best approach for creating widgets (type of
> > elements) with Cake. What I mean by widgets is basically elements that
> > pull data from something that may not relate to the current controller/
> > action the user is in.
>
> > For example, the default layout may have a sidebar of widgets. So when
> > someone is on the home page of the cake app, the sidebar may load the
> > following widgets on the left column sidebar as an example:
>
> > top 5 news stories
> > top 10 videos
> > random photo
> > random post
>
> > All of those "widgets" (ie: elements) would be pulling data from
> > several different models (news from Story, videos from Video, photo
> > from Photo, and so on). Is requestAction the best approach to
> > achieving something like this? I heard requestAction is heavy on
> > resources. Is there another "cake way" of doing this?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



phpThumb Helper

2008-07-13 Thread DanielMedia

Hi all,

Just added an article to the bakery. Its a phpThumb helper with cache
support for 1.2:

http://bakery.cakephp.org/articles/view/phpthumb-helper-2

Hope someone finds some use in it.

- Dan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



$this->Auth->user not refreshing after edit

2008-07-13 Thread RichardAtHome

Hi all :-)

I'm using Cake 1.2 and the Auth component.

Everything is working fine (after a bit of fiddling and manual
reading), but...

It looks like the Users model is only being read once at login and the
details stored in a session (not checked the cake code, but that would
match the behaviour I am experiencing).

Basically, the edit is working (ie, database gets updated), but the
$this->Auth->user() isn't.

This means, that if the user edits his profile (users table) the
changes are not reflected on the site until the user logs out and logs
back in again.

For security reasons (changes to role etc.) shouldn't the user model
be re-read on every page view and only the user id stored in the
session?

In the meantime, how do I get the Auth component to re-read the users
table after an edit?

Thanks in advance
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How can i filter Results so that only rows ( Records ) with a especific condition, like Result.is_final=1, are available for select.

2008-07-13 Thread PaulMan

Done.. where's how:
New version of: class Event extends AppModel
{
var $name = 'Event';
var $displayField= 'description';
var $belongsTo=array('Pool','Result' => array(
'className'=> 'Result',
'conditions' => 'Result.is_final=1'
));

 }

New Version of scaffold.php on line 311
foreach ($this->ScaffoldModel->belongsTo as $assocName => $assocData)
{
$varName = 
Inflector::variable(Inflector::pluralize(preg_replace('/
_id$/', '', $assocData['foreignKey'])));
$this->controller->set($varName, 
$this->ScaffoldModel-
>{$assocName}->find('list',$assocData));
}
foreach ($this->ScaffoldModel->hasAndBelongsToMany as 
$assocName =>
$assocData) {
$varName = 
Inflector::variable(Inflector::pluralize($assocName));
$this->controller->set($varName, 
$this->ScaffoldModel-
>{$assocName}->find('list',$assocData));
}

this way i can use params defined on var $belongsTo or
hasAndBelongsToMany ...

now the problem is... is this going to "f***" all the rest or is a
good hack?

On 13 Jul, 17:28, PaulMan <[EMAIL PROTECTED]> wrr ote:
> thank's for the quick reply,
> i already had read that articles, but i did no found the solution, the
> problem is on the "Edit" action for events, that's where i want to
> filter results, so that the final user can select a restrict options
> of results.
> Or maybe the solution is there and i'm too "newbie" blind to see, ???
> if this is true  please , sorry.
>
> lets put in another way:
> take a look at the debug query bellow , at Nr 8 i would like to have
> 8       SELECT `Result`.`id`, `Result`.`description` FROM `results` AS
> `Result` WHERE Result.is_active = 1             7       7       0
>
> so this way on the edit action , Results select box will be only
> populated with Results that are active, not all of them.
>
> since i'm with scaffold , is this possible?
>
> Nr      Query   Error   Affected        Num. rows       Took (ms)
> 1       DESCRIBE `events`               8       8       2
> 2       DESCRIBE `pools`                10      10      2
> 3       DESCRIBE `results`              6       6       2
> 4       DESCRIBE `bets`         6       6       2
> 5       DESCRIBE `users`                10      10      2
> 6       SELECT COUNT(*) AS `count` FROM `events` AS `Event` WHERE
> `Event`.`id` = 1                1       1       1
> 7       SELECT `Event`.`id`, `Event`.`pool_id`, `Event`.`result_id`,
> `Event`.`description`, `Event`.`comment`, `Event`.`date`,
> `Event`.`created`, `Event`.`modified`, `Result`.`id`,
> `Result`.`is_final`, `Result`.`description`, `Result`.`value`,
> `Result`.`created`, `Result`.`modified`, `Pool`.`id`,
> `Pool`.`description`, `Pool`.`comment`, `Pool`.`number`, `Pool`.`open
> date`, `Pool`.`close date`, `Pool`.`active`, `Pool`.`season`,
> `Pool`.`created`, `Pool`.`modified` FROM `events` AS `Event` LEFT JOIN
> `results` AS `Result` ON (`Result`.`is_final`=1 AND
> `Event`.`result_id` = `Result`.`id`) LEFT JOIN `pools` AS `Pool` ON
> (`Event`.`pool_id` = `Pool`.`id`) WHERE `Event`.`id` = 1 LIMIT 1              
>   1       1
> 1
> 8       SELECT `Result`.`id`, `Result`.`description` FROM `results` AS
> `Result` WHERE 1 = 1            7       7       0
> 9       SELECT `Pool`.`id`, `Pool`.`description` FROM `pools` AS `Pool`
> WHERE 1 = 1
>
> On 13 Jul, 16:36, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
>
> > Perhaps you should start reading 
> > here:http://book.cakephp.org/view/78/associations-linking-models-toandget
> > a grasp of models relations and how to specify conditions. Then you
> > can use bakehttp://book.cakephp.org/view/113/code-generation-with-bake
> > to materialize the scaffold code and start coding the application
> > logic
>
> > On Sun, Jul 13, 2008 at 12:18 PM, PaulMan <[EMAIL PROTECTED]> wrote:
>
> > > Hello Everyone,
> > > Using Scaffold,
> > > I Have a Model "Event" that belongsTo Result.
> > > The Problem is when i edit an Event How can i filter Results so that
> > > only rows ( Records ) with a especific condition, like
> > > Result.is_final=1, are available for select.
>
> > > class EventsController extends AppController {
> > > var $name = 'Events';
> > > var $components=array("auth");
> > >  var $scaffold;
> > > }
>
> > > class Event extends AppModel
> > > {
> > >    var $name = 'Event';
> > >        var $displayField= 'description';
> > >        var $belongsTo=array('Pool','Result' => array(
> > >            'className'    => 'Result',
> > >            'foreignKey'    => 'result_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

Re: CAKE PHP on BLUEHOST servers

2008-07-13 Thread Gonzalo Servat
On Sun, Jul 13, 2008 at 6:08 PM, JBMGT <[EMAIL PROTECTED]> wrote:

>
> HI,
>
> We have moved from one webhosting company to another one and now the
> site doesnt come up. It has been built in the CAKE PHP framework and I
> am hoping that someone with CAKE PHP experience on a BlueHost
> enviromnet can hint us what to look at.
>

[..snip..]

Just a word of advice: it's pretty much impossible for anybody to help you
unless you provide more information (eg. what actually happens? cakephp
version? error messages? anything in apache logs?). If you show the results
of the investigating you've done with your "technical" friends it may avoid
suggestions that you've already done.
Ensure that you have the 'debug' setting in app/config/core.php set to at
least 1.

- Gonzalo

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



CAKE PHP on BLUEHOST servers

2008-07-13 Thread JBMGT

HI,

We have moved from one webhosting company to another one and now the
site doesnt come up. It has been built in the CAKE PHP framework and I
am hoping that someone with CAKE PHP experience on a BlueHost
enviromnet can hint us what to look at.

All the files are sitting where they sat on the other domain as far as
the customer specific files. The cake php folder was later placed. We
placed it in the webroot as well as other areas.

We have also copied the php.ini file in various directories

I am thinking it maybe something small (i hope), but my "technical"
friends and I cannot figure it out

Anybody some hints and tips for us

It is greatly appreciated

With kind regards
RJ from JBMGT

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: CakePHP and widgets

2008-07-13 Thread Mark (Germany)

thats really a good question
i would like to know that mysefl

i found out though, that requesting might not be the best...
the database querys went up by 30%
especially if you get config details and session infos from the
Database,
they will be requested as often as you use this "requestAction" thing

makes sense, because it includes these widgets as n external source
reforcing sessionstart etc.

as soon as i found out, i started to work with controllers, which get
there information
from the models

dont know if theres a better solution
but i dont wanna have 24 querys where 12 are possibly



On 13 Jul., 23:01, Steve <[EMAIL PROTECTED]> wrote:
> Hey,
>
> I was wondering what the best approach for creating widgets (type of
> elements) with Cake. What I mean by widgets is basically elements that
> pull data from something that may not relate to the current controller/
> action the user is in.
>
> For example, the default layout may have a sidebar of widgets. So when
> someone is on the home page of the cake app, the sidebar may load the
> following widgets on the left column sidebar as an example:
>
> top 5 news stories
> top 10 videos
> random photo
> random post
>
> All of those "widgets" (ie: elements) would be pulling data from
> several different models (news from Story, videos from Video, photo
> from Photo, and so on). Is requestAction the best approach to
> achieving something like this? I heard requestAction is heavy on
> resources. Is there another "cake way" of doing this?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



CakePHP and widgets

2008-07-13 Thread Steve

Hey,

I was wondering what the best approach for creating widgets (type of
elements) with Cake. What I mean by widgets is basically elements that
pull data from something that may not relate to the current controller/
action the user is in.

For example, the default layout may have a sidebar of widgets. So when
someone is on the home page of the cake app, the sidebar may load the
following widgets on the left column sidebar as an example:

top 5 news stories
top 10 videos
random photo
random post

All of those "widgets" (ie: elements) would be pulling data from
several different models (news from Story, videos from Video, photo
from Photo, and so on). Is requestAction the best approach to
achieving something like this? I heard requestAction is heavy on
resources. Is there another "cake way" of doing this?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: ma a newbie - want to know how to install and create my first app..

2008-07-13 Thread AssiuM
Take a look at http://book.cakephp.org/view/219/blog

2008/7/13 xelios <[EMAIL PROTECTED]>:

>
> ma a newbie - want to know how to install and create my first app..
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: What happened to $params?.. API says it should exist.

2008-07-13 Thread Smelly_Eddie

I figured it out, thanks though!

$params=$this->params;



On Jul 13, 12:30 pm, Smelly_Eddie <[EMAIL PROTECTED]> wrote:
> I just upgraded to 1.2 Rc2.
>
> THe only real issue I have left is the missing variable $params in
> Views.
>
> This worked in 1.1, and the API for cake 1.2 rc says it still should,
> but my views display the error,
>
> Notice (8): Undefined variable: params [APP/views/layouts/default.ctp,
> line 109]
> Notice (8): Undefined variable: params [APP/views/layouts/default.ctp,
> line 114]
>
> The only way i can get around it is by adding $this->set('params',
> $this->params); to the controllers before render function.
>
> Any suggestions for me? (appreciated)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Documentation

2008-07-13 Thread keymaster

SaveAll() on related models is an extremely useful function which has
not been documented in the cookbook, or FAQ, only sparsely in the API,
and neither has much been written about it in these forums.

This might help as a starting point for documentation efforts:

http://blog.matsimitsu.nl/code/164/saveall-with-cakephp
http://blog.matsimitsu.nl/code/166/saveall-with-cakephp-part2

Sorry, couldn't find much else - a few scattered forum posts, nothing
remotely definitive, though.

The testcases might be another source of info until documentation
cmes out (fwiw).

Examples might include: the data array format to pass in for the
different relationships (hasOne, belongsTo, hasMany, HABTM); the max
levels deep (if any) it can be; is there a way to validateAll
independant of SaveAll(); inserting vs updating, specifying whitelists
for each model, etc
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Documentation

2008-07-13 Thread keymaster

SaveAll() on related models is an extremely useful function which has
not been documented in the cookbook, only sparsely in the API, and
neither has much been written about it in these forums.

This might help as a starting point for documentation efforts:

http://blog.matsimitsu.nl/code/164/saveall-with-cakephp
http://blog.matsimitsu.nl/code/166/saveall-with-cakephp-part2

Sorry, couldn't find much else - a few scattered forum posts, nothing
remotely definitive, though.

The testcases might be another source of info until documentation
comes out (fwiw)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



What happened to $params?.. API says it should exist.

2008-07-13 Thread Smelly_Eddie

I just upgraded to 1.2 Rc2.

THe only real issue I have left is the missing variable $params in
Views.

This worked in 1.1, and the API for cake 1.2 rc says it still should,
but my views display the error,

Notice (8): Undefined variable: params [APP/views/layouts/default.ctp,
line 109]
Notice (8): Undefined variable: params [APP/views/layouts/default.ctp,
line 114]

The only way i can get around it is by adding $this->set('params',
$this->params); to the controllers before render function.


Any suggestions for me? (appreciated)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How can i filter Results so that only rows ( Records ) with a especific condition, like Result.is_final=1, are available for select.

2008-07-13 Thread PaulMan

thank's for the quick reply,
i already had read that articles, but i did no found the solution, the
problem is on the "Edit" action for events, that's where i want to
filter results, so that the final user can select a restrict options
of results.
Or maybe the solution is there and i'm too "newbie" blind to see, ???
if this is true  please , sorry.


lets put in another way:
take a look at the debug query bellow , at Nr 8 i would like to have
8   SELECT `Result`.`id`, `Result`.`description` FROM `results` AS
`Result` WHERE Result.is_active = 1 7   7   0

so this way on the edit action , Results select box will be only
populated with Results that are active, not all of them.

since i'm with scaffold , is this possible?



Nr  Query   Error   AffectedNum. rows   Took (ms)
1   DESCRIBE `events`   8   8   2
2   DESCRIBE `pools`10  10  2
3   DESCRIBE `results`  6   6   2
4   DESCRIBE `bets` 6   6   2
5   DESCRIBE `users`10  10  2
6   SELECT COUNT(*) AS `count` FROM `events` AS `Event` WHERE
`Event`.`id` = 11   1   1
7   SELECT `Event`.`id`, `Event`.`pool_id`, `Event`.`result_id`,
`Event`.`description`, `Event`.`comment`, `Event`.`date`,
`Event`.`created`, `Event`.`modified`, `Result`.`id`,
`Result`.`is_final`, `Result`.`description`, `Result`.`value`,
`Result`.`created`, `Result`.`modified`, `Pool`.`id`,
`Pool`.`description`, `Pool`.`comment`, `Pool`.`number`, `Pool`.`open
date`, `Pool`.`close date`, `Pool`.`active`, `Pool`.`season`,
`Pool`.`created`, `Pool`.`modified` FROM `events` AS `Event` LEFT JOIN
`results` AS `Result` ON (`Result`.`is_final`=1 AND
`Event`.`result_id` = `Result`.`id`) LEFT JOIN `pools` AS `Pool` ON
(`Event`.`pool_id` = `Pool`.`id`) WHERE `Event`.`id` = 1 LIMIT 1
1   1
1
8   SELECT `Result`.`id`, `Result`.`description` FROM `results` AS
`Result` WHERE 1 = 17   7   0
9   SELECT `Pool`.`id`, `Pool`.`description` FROM `pools` AS `Pool`
WHERE 1 = 1

On 13 Jul, 16:36, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
> Perhaps you should start reading 
> here:http://book.cakephp.org/view/78/associations-linking-models-toand get
> a grasp of models relations and how to specify conditions. Then you
> can use bakehttp://book.cakephp.org/view/113/code-generation-with-bake
> to materialize the scaffold code and start coding the application
> logic
>
> On Sun, Jul 13, 2008 at 12:18 PM, PaulMan <[EMAIL PROTECTED]> wrote:
>
> > Hello Everyone,
> > Using Scaffold,
> > I Have a Model "Event" that belongsTo Result.
> > The Problem is when i edit an Event How can i filter Results so that
> > only rows ( Records ) with a especific condition, like
> > Result.is_final=1, are available for select.
>
> > class EventsController extends AppController {
> > var $name = 'Events';
> > var $components=array("auth");
> >  var $scaffold;
> > }
>
> > class Event extends AppModel
> > {
> >    var $name = 'Event';
> >        var $displayField= 'description';
> >        var $belongsTo=array('Pool','Result' => array(
> >            'className'    => 'Result',
> >            'foreignKey'    => 'result_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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Question about locales and their correct way of using

2008-07-13 Thread Dardo Sordi Bogado

On Sat, Jun 28, 2008 at 5:03 PM, Mark (germany)
<[EMAIL PROTECTED]> wrote:
>
> I started to translate some of the
> "hello, nice to have you back" oder "This is the Page about Mosquitos"
> into GERMAN, etc.
>
> now..
> first of all, some of the translations can get pretty long - and have
> to be in the source code
> wouldn't it be more logic, to set short names like MESSAGE_HELLO etc
> (like its done with constants in some cms oder oscommerce etc) and
> referring to the .po file - where the complete message is?
>
> __(Configure::load() - %s.php not found)
> and
> msgid "Configure::load() - %s.php not found"
>
> would be
> __(CONFIG_NOTFOUND)
> and
> msgid "Configure::load() - %s.php not found"

That is a bad practice, may be good for programmers but is terrible
for translators.

http://www.gnu.org/software/gettext/manual/gettext.html#Preparing-Strings

>
> this way the content of the transcription can slidly change in the
> original language (eng), without having to adapt it to the other
> languages
> the pages and templates should become smaller - and the .po file stays
> the same.
>
> so if you change
> __(Configure::load() - %s.php not found) to __(Configure::load() -
> %s.php cannot be found)
> you usually have to change ALL other language files
>
> with my idea you probably stick to this one change in one language
>
> what i want to say is that it might be useful to stick to short and
> clear placeholder, so to speak.
> what do you say about that?
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: transaction

2008-07-13 Thread Marcin Domanski

Maybe your database doesnt support transactions ?
--
Marcin Domanski
http://kabturek.info


On Sun, Jul 13, 2008 at 10:39 AM, . <[EMAIL PROTECTED]> wrote:
> I have the following transaction, but even on errors, it does not rollback.
> Why?
>
> $this->List->begin();
> $this->List->create();
> $this->data['List']['id']=1;
> ... do so more set up
> $this->List->save($this->data)
>
> if (...is okay...)
> $this->List->commit();
> else
> $this->List->rollback();
>
> do i have the right syntax? I manually force the $this->List->rollback() to
> execute, but  I still see the record in the database. Why?
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: ma a newbie - want to know how to install and create my first app..

2008-07-13 Thread Easter Egg

You can start with book.cakephp.org, and search google for "cakephp
blog tutorial"!

be more specific, I do whatever I can.

On Jul 13, 11:08 am, xelios <[EMAIL PROTECTED]> wrote:
> ma a newbie - want to know how to install and create my first app..
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: CakeAMFPHP with Cake 1.2

2008-07-13 Thread morris

Thanks to John's help I now have CakeAMFPHP 0.6.0 running in my cake
1.2 app.

For anyone else looking to achieve this please check out:
http://bakery.cakephp.org/articles/view/using-cakeamfphp-0-6-w-cake-1-2

On Jul 8, 1:57 pm, morris <[EMAIL PROTECTED]> wrote:
> sorry, guess I should have clarified. We are still using the 
> oldcakeamfphpproject (.6) .. not the new "cakeamf" project.
>
> The reason we are doing this is because I don't have access to the
> flash source at this time, and I'm unsure if I will need to be making
> any edits to the flash/as if we are to upgrade fromCakeAMFPHP0.6 to
> CakeAMF (apart from the gateway connection which is set dynamically).
>
> I was hoping to simply getCakeAMFPHPrunning with the Cake 1.2
> upgrade I just did, but our flash movies are all timing out their
> connections.
>
> Do you have any experience with runningCakeAMFPHP(the old one) in
> cake 1.2? If so, what was the process of manually upgradingCakeAMFPHP?
>
> Do you instead recommend setting up the new 'CakeAMF'? I tried it out
> briefly but our flash movies were still timing out. I'm not sure if
> the gateway was set up correctly though I followed all directions. I
> set up the amfext in php, added the 'amf' plugin to my app, imported
> it into webroot/index.php, then included as component in
> app_controller (as 'Amf.Amf'), and set my gateway to the root of the
> app (/). This, unfortunately, did not resolve anything.
>
> Thanks again for your time and help here
>
> -morris
>
> On Jul 8, 1:12 pm, John David Anderson <[EMAIL PROTECTED]>
> wrote:
>
> > I think you're using even an older version of Cakeamf than I am.
>
> > I'd suggest getting the latest goodness from SVN, and following the
> > instructions here:
>
> >https://trac.cakefoundation.org/amf/
>
> > -- John
>
> > On Jul 8, 2008, at 10:48 AM, morris wrote:
>
> > > So you're suggesting I move the following lines from /webroot/
> > > cake_gateway.php
>
> > > -- loadController (null);  see below
> > > -- vendor('cakeamfphp'.DS.'amf-core'.DS.'app'.DS."CakeGateway"); see
> > > below
>
> > > into /webroot/index.php as
>
> > > -- App::import('Controller', null);
> > > -- App::import('Vendor', 'CakeGateway', null, null,
> > > 'cakeamfphp'.DS.'amf-core'.DS.'app'.DS."CakeGateway.php");
>
> > > ?
>
> > > I would certainly appreciate some help here if there is more to it
> > > than this. Feel free to PM me.
>
> > > Thanks!
>
> > > On Jul 8, 12:06 pm, John David Anderson <[EMAIL PROTECTED]>
> > > wrote:
> > >> On Jul 8, 2008, at 9:29 AM, morris wrote:
>
> > >>> I'm having a heck of a time trying to getCakeAMFPHP0.6 working
> > >>> with
> > >>> a cake 1.2 site. We had been working with cake 1.1 andCakeAMFPHP,
> > >>> which was doing fine. I've spent the past week upgrading our site
> > >>> for
> > >>> 1.2 and everything is working extremely well -- except our flash
> > >>> bits
> > >>> have ceased to work.
>
> > >>> Unfortunately our team is now lacking the flash expert who had set
> > >>> all
> > >>> the flash stuff up, otherwise I wouldn't be here. I'm hoping that
> > >>> there may be some folk out there who have also chosen to simply
> > >>> overhaul theircakeamfphpto work in the 1.2 environment, like us.
> > >>> (I'd love to move to CakeAMF but I don't have the wherewithall to
> > >>> break open our flash files and retool them).
>
> > >>> I modified the cake_gateway.php file to be using the correct
> > >>> App::import methods, and debug var, which when visited tells me it
> > >>> is
> > >>> set up correctly. The problem seems to be that the flash movies are
> > >>> all timing out.
>
> > >>> Is there anything that anyone can tell me about the process for re-
> > >>> toolingcakeamfphpto work in cake 1.2?
>
> > >> The App::import() call is now in index.php due to some path loading
> > >> changes since earlier versions of cake. I can help if you need it.
>
> > >> -- John
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: database convention

2008-07-13 Thread Dardo Sordi Bogado

> Absolute noob here. I have a question about cakePhp database
> convention. From my understanding of the manual, every table requires
> a single attribute primary key.
>
> So, in a table where you might normally have a composite key with two
> attributes, you should add an 'artificial identifier' as a single-
> attribute primary key for each tuple, and use that rather than the
> composite key.
>
> Firstly, have I got that right?

Yes, you got that right. For some people it sounds dirty but it
simplifies things a lot.

> Secondly, do people tend to use AUTO INCREMENT a lot to implement such
> functionality in their databases?

And yes again for the same reason. But it's no mandatory, you can set
the keys on your own and make your development more cumbersome.

Also UUIDS are supported (and are great) as primary keys, you can set
the primary key to be char(36) and cake will take care of it:
http://book.cakephp.org/complete/3/the-manual

> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How can i filter Results so that only rows ( Records ) with a especific condition, like Result.is_final=1, are available for select.

2008-07-13 Thread Dardo Sordi Bogado

Perhaps you should start reading here:
http://book.cakephp.org/view/78/associations-linking-models-to and get
a grasp of models relations and how to specify conditions. Then you
can use bake http://book.cakephp.org/view/113/code-generation-with-bake
to materialize the scaffold code and start coding the application
logic.

On Sun, Jul 13, 2008 at 12:18 PM, PaulMan <[EMAIL PROTECTED]> wrote:
>
> Hello Everyone,
> Using Scaffold,
> I Have a Model "Event" that belongsTo Result.
> The Problem is when i edit an Event How can i filter Results so that
> only rows ( Records ) with a especific condition, like
> Result.is_final=1, are available for select.
>
>
> class EventsController extends AppController {
> var $name = 'Events';
> var $components=array("auth");
>  var $scaffold;
> }
>
>
>
> class Event extends AppModel
> {
>var $name = 'Event';
>var $displayField= 'description';
>var $belongsTo=array('Pool','Result' => array(
>'className'=> 'Result',
>'foreignKey'=> 'result_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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Need help with foreign keys in setting up a messaging system

2008-07-13 Thread Dardo Sordi Bogado

Set both associations with different aliases and different foreign
keys but same class (User).

On Sat, Jul 12, 2008 at 3:46 PM, Siebren Bakker
<[EMAIL PROTECTED]> wrote:
> I would like to set up a system for my users to be able to message each
> other, and know how I would do so, but am not sure on the database/cake part
> of things. I have a messages model, view, and controller, but am unsure how
> to set up the database, and model associations for this, as there is a user
> associated with the originating user as well as the receiving user, and the
> ids for both of those columns would be pulled from my users table.
>
> I was wondering if anyone had any experience with this sort of thing, or
> would be able to point me in the right direction to setting up a system
> similar to this.
> In the name of Life, Liberty, and the pursuit of my sanity.
> Siebren Bakker(Aevum Decessus)
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



ma a newbie - want to know how to install and create my first app..

2008-07-13 Thread xelios

ma a newbie - want to know how to install and create my first app..

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



How can i filter Results so that only rows ( Records ) with a especific condition, like Result.is_final=1, are available for select.

2008-07-13 Thread PaulMan

Hello Everyone,
Using Scaffold,
I Have a Model "Event" that belongsTo Result.
The Problem is when i edit an Event How can i filter Results so that
only rows ( Records ) with a especific condition, like
Result.is_final=1, are available for select.


class EventsController extends AppController {
var $name = 'Events';
var $components=array("auth");
 var $scaffold;
}



class Event extends AppModel
{
var $name = 'Event';
var $displayField= 'description';
var $belongsTo=array('Pool','Result' => array(
'className'=> 'Result',
'foreignKey'=> 'result_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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: One to many forms with ajax

2008-07-13 Thread Andraž

Hm, I see, that i didn't reply to this post. :(

http://groups.google.com/group/cake-php/browse_thread/thread/3f707d87836750ab

On Jul 12, 9:12 pm, Andraž <[EMAIL PROTECTED]> wrote:
> Did you find the solution?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: 1 model 3 tables

2008-07-13 Thread Dardo Sordi Bogado

On Sun, Jul 13, 2008 at 10:27 AM, the_woodsman <[EMAIL PROTECTED]> wrote:
>
> I can think of a few reasons- perhaps to abstract a complex database
> relationship into a single entity in most of the codebase?
>
> A model can use its related tables, i.e if Post hasMany Comments, in
> the Post model you can use $this->Comment.
>
> You can also load arbitrary models on the fly using App::import.
>
> And of course you can do this abstraction at the DB level using a
> MySQL view to join tables.
>
> If Dardo has any other tricks for this, I'd be interested too!
>

I was thinking in set $this->useTable and overriding the
Model::schema() to do a caching in a table basis (or force reloading).

>
>
> On Jul 12, 3:27 pm, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
>> > it's possible to use one model with more than one different tables?
>>
>> Technically yes, but doesn't make any sense. Can you explain why?
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



database convention

2008-07-13 Thread onefootswill

Absolute noob here. I have a question about cakePhp database
convention. From my understanding of the manual, every table requires
a single attribute primary key.

So, in a table where you might normally have a composite key with two
attributes, you should add an 'artificial identifier' as a single-
attribute primary key for each tuple, and use that rather than the
composite key.

Firstly, have I got that right?

Secondly, do people tend to use AUTO INCREMENT a lot to implement such
functionality in their databases?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: 1 model 3 tables

2008-07-13 Thread the_woodsman

I can think of a few reasons- perhaps to abstract a complex database
relationship into a single entity in most of the codebase?

A model can use its related tables, i.e if Post hasMany Comments, in
the Post model you can use $this->Comment.

You can also load arbitrary models on the fly using App::import.

And of course you can do this abstraction at the DB level using a
MySQL view to join tables.

If Dardo has any other tricks for this, I'd be interested too!




On Jul 12, 3:27 pm, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
> > it's possible to use one model with more than one different tables?
>
> Technically yes, but doesn't make any sense. Can you explain why?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: another transaction question

2008-07-13 Thread James K

The way transactions work, they aren't scoped to any one model. When
you call model::begin, it sends a "Start Transaction" command to your
database, and then any queries passed after that point (via any model)
are all contained in that single transaction. You can call commit from
any model, and it will commit all the queries regardless of which
model sent them.

Also I prefer using try/catch blocks for running transactions as well
- it's cleaner and much easier to maintain than all sorts of nested
ifs:

try {
$this->modelA->create($this->data['modelA']);
$this->modelA->modelAB->create($this->data['modelAB']);

if (!($this->modelA->save()))
throw Exception('Model A save failed');

if (!($this->modelA->modelAB->save()))
throw Exception('Model AB save failed');

$this->modelA->commit();

} catch (Exception $e) {
$this->modelA->rollback();
}

- James

On Jul 13, 4:44 am, . <[EMAIL PROTECTED]> wrote:
> if I have more than 2 models A, B, and C, do i need to do a
> $this->[model]->begin() for all of the models, or just the first model?
>
> for example, do I need to do this:
>
> $this->A->begin()
> $this->B->begin()
> .
> if ($this->A->save(...))
> {
>     if ($this->B->save(...))
>     {
>           if ($this->C->save(...))
>           {
>                 $this->A->commit();
>                 $this->B->commit();
>           }
>           else
>           {
>                $this->A->rollback();
>                $this->B->rollback();
>           }
>     }
>
> }
>
> Or, can I just do this?
>
> $this->A->begin()
> .
> if ($this->A->save(...))
> {
>     if ($this->B->save(...))
>     {
>           if ($this->C->save(...))
>           {
>                 $this->A->commit();
>           }
>           else
>           {
>                $this->A->rollback();
>           }
>     }
>
> }
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



another transaction question

2008-07-13 Thread .
if I have more than 2 models A, B, and C, do i need to do a
$this->[model]->begin() for all of the models, or just the first model?

for example, do I need to do this:

$this->A->begin()
$this->B->begin()
.
if ($this->A->save(...))
{
if ($this->B->save(...))
{
  if ($this->C->save(...))
  {
$this->A->commit();
$this->B->commit();
  }
  else
  {
   $this->A->rollback();
   $this->B->rollback();
  }
}
}

Or, can I just do this?

$this->A->begin()
.
if ($this->A->save(...))
{
if ($this->B->save(...))
{
  if ($this->C->save(...))
  {
$this->A->commit();
  }
  else
  {
   $this->A->rollback();
  }
}
}

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



transaction

2008-07-13 Thread .
I have the following transaction, but even on errors, it does not rollback.
Why?

$this->List->begin();
$this->List->create();
$this->data['List']['id']=1;
... do so more set up
$this->List->save($this->data)

if (...is okay...)
$this->List->commit();
else
$this->List->rollback();

do i have the right syntax? I manually force the $this->List->rollback() to
execute, but  I still see the record in the database. Why?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM Save Issues

2008-07-13 Thread Novice Programmer
Hello,

I aplogize for the confusing statements.. let me try to explain further

I am trying to save the model plus the assoc. User can have many favorites
but at a time he can mark only one of them as a favorite. So when a user
marks some entity as a favorite i need to perform the following things:

1. check if the entity exists in the favorites table. If it exists there
then i note the id where it exists, if it does not exist there i need to
insert that entity into the favorites table. By both the methods i get the
favorite id. and with the following statement in the favorite behavior i set
the id of the favorite.
$model->data['Favorite']['id'] = $id;

I think that there can be some thing to do this stuff automagically.

2. The association works. but it works only if i write the data as:

save_data['User']['entity_id']=$entity_id
but as you can see entity_id is not an attribute of user data, it is an
attribute of favorite table, so i should write:
save_data['Favorite']['entity_id']=$entity_id

and then call save on the user model, but when i use 'favorite' instead of
'user' nothing works at all. i am confused on why it does not work when it
is a field of Favorite only.

and yeah AJAX has got no problems at all. The problem is with how to save
model+assoc.

I hope i were clear. If not lets take an example of how you tube might
implement the favoriting of videos by the users.

Thanks.

On 7/8/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
> It is not exactly the easiest to follow exactly what you have a
> problem with. Guess that may be why no-one has come to the rescue.
>
> You should strip your code and your question down to the root issue.
> This makes it much easier to follow your reasoning, plus it show that
> you have "done your homework", which is always a good thing.
>
> For example. Issues with saving HABTM records has nothing to do with
> Ajax. If it works without Ajax then you probably have a problem
> related to Ajax and not specifically HABTM associations.
>
> What specifically are you trying to save? (Model+assoc?, just the
> assoc?, multiple assoc?)
> What is the association you are having a problem with? (I.E. if User
> HABTM Favorite why mention Eitity at all?)
> Is the association working? (I.E. manually pushing data into the
> database. Does it link up OK in the Models?)
>
> Also, if you make a test setup without ajax, behaviors and anything
> but form->controller->model you have eliminated a bunch of variables
> and probably made the code more readable to others.
>
> try to clarify and hopefully I (or someone else) may be abel to
> understand your problem and be of help.
> /Martin
>
>
> On Jul 7, 9:07 pm, "Novice Programmer" <[EMAIL PROTECTED]>
> wrote:
> > No one to the rescue?
> >
> > Thanks.
> >
> > On Mon, Jul 7, 2008 at 9:50 PM, Novice Programmer <
> [EMAIL PROTECTED]>
> > wrote:
> >
> >
> >
> > > Hello again,
> >
> > > I am stuck with the HABTM save/retrieval.. Please help.. I have got
> three
> > > models.
> >
> > > 1. Entitiy (id auto_increment)
> > > 2. User (id auto_increment)
> > > 3. Favorite(id auto_increment, entity_id)
> >
> > > A user can have many favorite entities and a favorite can belong to
> many
> > > users.. so i have created a HABTM table users_favorites (user_id,
> > > favorite_id).
> > > I have defined the relationship as follows in the User Model.
> >
> > > var $hasAndBelongsToMany = array(
> > > 'Favorite' =>
> > > array('className'=> 'Favorite',
> > > 'joinTable'  => 'users_favorites',
> > > 'foreignKey' => 'user_id',
> > > 'associationForeignKey'  => 'favorite_id',
> > > 'conditions' => '',
> > > 'order'  => '',
> > > 'limit'  => '',
> > > 'unique'   => false,
> > > 'finderQuery'  => '',
> > > 'deleteQuery'=> '',
> > > 'insertQuery' => ''
> > > )
> >
> > > I provide an AJAX link to the user to favorite an entity like
> > > http:///users/favorite/entity_id users/favorite/entity_id>
> > > .
> >
> > > In the users_controller, I have written teh following.
> >
> > > $user_id = $this->Auth->user('id');
> > > $this->User->Behaviors->Attach(Behavior);
> > > *save_data['User']['entity_id']=$entity_id;*
> > > $this->User->save($save_data);
> >
> > > In the favorites behavior:
> >
> > > *function beforeSave($&model) {*
> > > *$Favorite = new $Favorite;*
> > > **
> > > *if ($res = $Favorite->find($model->data['User']['entity_id'])) {*
> > > *$id = $res['Favorite']['id'];*
> > > *}*
> > > *else {*
> > > *$Favorite->save(array('id'=>"", 'entity_id' =>
> > > $model->data['User']['entity_id']));*
> > > *$id = $Favorite->getLastInsertID();*
> > > *}*
> > > *$model->data['Favorite']['id'] = $id;*
> > > *}*
> > > *}