Retrieving information with a hasMany through (The Join Model) association.

2012-07-02 Thread Ronen Amiel
Hey everyone,

I'm I have a hasMany through (The Join Model) association on my 
application. I have 3 models in my application: students, courses and the 
join model: membership (used as a join model and also tracks grades). I'm 
trying to retrieve some information from the database, I want to get one 
course information along with all of it's students and their grades by 
calling: $this-Course-Membership-findAllByCourseId($id). In return I'm 
getting the following:

Array
(
[0] = Array
(
[Membership] = Array
(
[id] = 12
[student_id] = 9
[course_id] = 3
[grade] = 100
)
[Student] = Array
(
[id] = 9
[name] = Kyle
[created] = 2012-07-02 10:32:24
[modified] = 2012-07-02 12:44:37
)
[Course] = Array
(
[id] = 3
[name] = Math
[created] = 2012-07-02 10:31:17
[modified] = 2012-07-02 10:31:17
)
)
[1] = Array
(
[Membership] = Array
(
[id] = 14
[student_id] = 10
[course_id] = 3
[grade] = 86
)
[Student] = Array
(
[id] = 10
[name] = Butters
[created] = 2012-07-02 10:32:29
[modified] = 2012-07-02 12:44:41
)
[Course] = Array
(
[id] = 3
[name] = Math
[created] = 2012-07-02 10:31:17
[modified] = 2012-07-02 10:31:17
)
)
)

As you can see, the course information is duplicated across the whole 
array. Because the course information is the same for all of them, it's 
just pointless and wastes resources.
So, is there a way to retrieve data like that, by a specific parameter 
having information duplicated across the entire array?

Also, is there a way to use a HABTM association that also saves information 
such as: grades or days attended?

Thanks!

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Filter on a deep model association

2012-03-01 Thread lowpass
But the 2nd version would be pretty ugly because the Collection array
would be repeated for each Author. I think the first is the way to go
because what you're really doing is viewing a Collection. The Books
and Authors are secondary.

To sort the Authors, I think you might be able to use the Set class.
But, if you can, I doubt it would be simple because your array will
look like:

Collection
Book
Author // possibly more than one here
Book
Author // possibly more than one here
etc.

Then there's also the possibility that a given Author is associated
with more than one Book in this Collection. So I think it would more
sensible to order the Books within the Collection, and the Authors
within Book.

$data = $this-Author-Book-Collection-find(
'first',
array(
'conditions' = array(
'Collection.id' = $c_id
),
'contain' = array(
'Book' = array(
'order' = array('Book.title' = 'ASC'),
'Author' = array(
'order' = array('Author.surname' = 
'ASC'),
)
)
)
)
);

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Filter on a deep model association

2012-02-28 Thread whatsnew
Hi,
I have these 3 associated models :

class Author extends AppModel {
var $hasAndBelongsToMany = array('Book');
}

class Book extends AppModel {
var $belongsTo = array('Collection');
var $hasAndBelongsToMany = array('Author');
}

class Collection extends AppModel {
var $hasMany = array('Book');
}

I need to find the list of all the authors (with their associated
books) filtered by collection. I tried with the containable behaviour
but I can only filters on the Collection level.
Any help would be appreciated.

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Filter on a deep model association

2012-02-28 Thread lowpass
What do you mean by filtered? Do you want to sort by Collection, or do
you want to select only specific Collections?

And which controller/model do you want to do this from? Because the
models are associated, code from, eg. the Book model can run a find()
from the Collection model. $this-Book-Collection-find(...)

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Filter on a deep model association

2012-02-28 Thread whatsnew
By filter I mean to select all authors where Collection is equal to a
collection_id and do it from the authors controller.
I can't simply do a $this-Author-
find('all',array('conditions'=array('Collection.id'=
$collection_id)) because the Author model is not associated with the
Collection model.
Thanks for helping.

On 28 fév, 20:32, lowpass zijn.digi...@gmail.com wrote:
 What do you mean by filtered? Do you want to sort by Collection, or do
 you want to select only specific Collections?

 And which controller/model do you want to do this from? Because the
 models are associated, code from, eg. the Book model can run a find()
 from the Collection model. $this-Book-Collection-find(...)

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Filter on a deep model association

2012-02-28 Thread lowpass
Go 3 levels deep so the data is arranged by the particular Collection
you're after.

$data = $this-Author-Book-Collection-find(
'first',
array(
'conditions' = array(
'Collection.id' = $c_id
),
'contain' = array(
'Book' = array(
'Author'
)
)
)
);

Because the Book model has the collection_id you really only need to
go 2 models deep.

$data = $this-Author-Book-find(
'all',
array(
'conditions' = array(
'Book.collection_id' = $c_id
),
'contain' = array(
'Collection',
'Author'
)
)
);

But then the data will be arranged badly. Collection, for instance,
will be repeated for each Book.

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Filter on a deep model association

2012-02-28 Thread whatsnew
Your second proposition is close to what I need, but my Grail would be
to have the list of the authors (sorted alphabetically) each with its
associated books published in a given collection. I guess that with
some tweaking of the array of results I can get there but it's not
very elegant.
Thanks again.

On 28 fév, 23:16, lowpass zijn.digi...@gmail.com wrote:
 Go 3 levels deep so the data is arranged by the particular Collection
 you're after.

 $data = $this-Author-Book-Collection-find(
         'first',
         array(
                 'conditions' = array(
                         'Collection.id' = $c_id
                 ),
                 'contain' = array(
                         'Book' = array(
                                 'Author'
                         )
                 )
         )
 );

 Because the Book model has the collection_id you really only need to
 go 2 models deep.

 $data = $this-Author-Book-find(
         'all',
         array(
                 'conditions' = array(
                         'Book.collection_id' = $c_id
                 ),
                 'contain' = array(
                         'Collection',
                         'Author'
                 )
         )
 );

 But then the data will be arranged badly. Collection, for instance,
 will be repeated for each Book.

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom model association column

2012-02-25 Thread djogo
Hello all,

Your suggestions would work, however I`m trying to get a shortcut here
= eliminating the Subject.

is there any way that we could specify a join condition, like

'hasMany' = array(
 'model' = 'Contents',
 'join' = 'Contents.subject_id = HospitalAdmission.subject_id'

...
)


?

On Feb 22, 6:16 am, Stephen Speakman step...@ninjacodermonkey.co.uk
wrote:
 Something i need to bear in mind when mapping my models, no joining
 between two connections.

 Could you not find a behaviour to create a temporary table as a very
 last resort?

 Sent from my iPhone

 On 21 Feb 2012, at 21:37, jeremyharris funeralm...@gmail.com wrote:







  Does Containable not work?

  $this-HospitalAdmission-find('all', array(
    'contain' = array(
      'Subject' = array(
        'Contents'
      )
    )
  ));
  --
  Our newest site for the community: CakePHP Video 
  Tutorialshttp://tv.cakephp.org
  Check out the new CakePHP Questions sitehttp://ask.cakephp.organd
  help others with their CakePHP related questions.

  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.com For more options, visit this
  group athttp://groups.google.com/group/cake-php

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom model association column

2012-02-25 Thread jeremyharris
Cake will automatically build that condition based off of the current 
model's primary key and the foreignKey you specify in the $hasMany 
relationship. You can supply additional conditions using the 'conditions' 
key on that relationship.

$hasMany = array(
'Content' = array(
'foreignKey' = 'subject_id',
'conditions' = array('Content.something' = 'Subject.nothing')
);

On Saturday, February 25, 2012 9:40:51 AM UTC-8, djogo wrote:

 Hello all, 

 Your suggestions would work, however I`m trying to get a shortcut here 
 = eliminating the Subject. 

 is there any way that we could specify a join condition, like 

 'hasMany' = array( 
  'model' = 'Contents', 
  'join' = 'Contents.subject_id = HospitalAdmission.subject_id' 

 ... 
 ) 


 ? 

 On Feb 22, 6:16 am, Stephen Speakman step...@ninjacodermonkey.co.uk 
 wrote: 
  Something i need to bear in mind when mapping my models, no joining 
  between two connections. 
  
  Could you not find a behaviour to create a temporary table as a very 
  last resort? 
  
  Sent from my iPhone 
  
  On 21 Feb 2012, at 21:37, jeremyharris funeralm...@gmail.com wrote: 
  
  
  
  
  
  
  
   Does Containable not work? 
  
   $this-HospitalAdmission-find('all', array( 
 'contain' = array( 
   'Subject' = array( 
 'Contents' 
   ) 
 ) 
   )); 
   -- 
   Our newest site for the community: CakePHP Video Tutorialshttp://
 tv.cakephp.org 
   Check out the new CakePHP Questions sitehttp://ask.cakephp.organd 
   help others with their CakePHP related questions. 
  
   To unsubscribe from this group, send email to 
   cake-php+unsubscr...@googlegroups.com For more options, visit this 
   group athttp://groups.google.com/group/cake-php

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom model association column

2012-02-22 Thread Stephen Speakman
Something i need to bear in mind when mapping my models, no joining  
between two connections.


Could you not find a behaviour to create a temporary table as a very  
last resort?


Sent from my iPhone

On 21 Feb 2012, at 21:37, jeremyharris funeralm...@gmail.com wrote:


Does Containable not work?

$this-HospitalAdmission-find('all', array(
  'contain' = array(
'Subject' = array(
  'Contents'
)
  )
));
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and  
help others with their CakePHP related questions.



To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this  
group at http://groups.google.com/group/cake-php


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



To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Custom model association column

2012-02-21 Thread Diogo FC Patrao
Hi all

I have a data model like this:

*HospitalAdmission* belongsTo *Subject* hasMany *Contents*

That is, I have a subject_id column on HospitalAdmission, and a column with
the same name in Contents. Plus, HospitalAdmission is in one database, and
Subject and Contents in other, not being possible (for technical reasons)
to join them together in the same query.

I'd like to directly get all HospitalAdmissions linked to some Content, but
I only found documentation on how to specify the foreignKey of a hasMany
relation - in this case, I would have to specify hasMany not to look into
Content.id field.

I could do this programatically (by getting all subject_id from a
Content-find('all') and then HospitalAdmission-find('all')), or putting
the full relationship with Subject (which would be a little cumbersome, as
I don`t really need any information in this

any thoughts?

--
diogo patrão

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom model association column

2012-02-21 Thread jeremyharris
Does Containable not work?

$this-HospitalAdmission-find('all', array(
  'contain' = array(
'Subject' = array(
  'Contents'
)
  )
));

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Association and Find

2012-01-09 Thread jeremyharris
Since HABTM data is constructed as separate SQL statements, and not a JOIN, 
you cannot add conditions to the query directly. There are ways to get the 
data you want, though. Check out the example in the book[1] or search 
Google for cakephp find habtm data

1: http://book.cakephp.org/1.3/en/view/1044/hasAndBelongsToMany-HABTM

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Model Association and Find

2012-01-08 Thread Fernando Nery Filho
Hello all!

I've been programming in PHP for a while now but just started to use Cake
in this new project I'm working.
I have 3 Table I'd like to Associate together: Movies, Actors and Cast

My Movie Model is set the following way:

*public $hasAndBelongsToMany = array(*

*'Elenco' = array(*

*'className'  = 'Personalidade',*

*'joinTable'  = 'filmes_personalidades',*

*'foreignKey' = 'filme_id',*

*'associationForeignKey'  = 'personalidade_id',*

*'unique' = true,*

*'fields' = 'id,nome'*

*)*

);


When I use $this-Filme-find('all') it works fine and all the Actors are
selected correctly.
But when I try to filter movies that have a selected actor using:

*$this-set('filmes', $this-Filme-find('all', array(*

*'conditions' = array(Elenco.id = array($personalidade_id)),*

*'limit' = 20,*

*'page' = $pagina*

*)));*


Cake tells me *SQLSTATE[42S22]:* Column not found: 1054 Unknown column
'Elenco.id' in 'where clause'.

What am I doing wrong?
Thanks for the support in advance!

Fernando Nery Filho*
*

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


cake model association error

2011-06-22 Thread madusanka hettiarachchi
HI guys,

Im new to cake! I made a association between two models called Album and
Subalbum.
association should be like this,

Subalbum hasOne Album
Album hasMany Subalbums

bt I got error like this,
*
1054: Unknown column 'Album.subalbum_id' in 'on clause'
[CORE\cake\libs\model\datasources\dbo_source.php, line 684]

*SELECT `Subalbum`.`id`, `Subalbum`.`sub_album_name`,
`Subalbum`.`date_created`, `Subalbum`.`last_modified_date`,
`Subalbum`.`music_id`, `Subalbum`.`size`, `Subalbum`.`album_id`,
`Album`.`id`, `Album`.`album_name`, `Album`.`sub_directory`,
`Album`.`create_date`, `Album`.`last_modified_date`, `Album`.`music_id`,
`Album`.`album_category`, `Album`.`album_description`, `Album`.`user_id`,
`Album`.`size` FROM `subalbums` AS `Subalbum` LEFT JOIN `albums` AS `Album`
ON (`Album`.`subalbum_id` = `Subalbum`.`id`)  WHERE 1 = 1

error occuerd due to highlighted part of the query, it should be
(`Album`.`subalbum_id`
= `Subalbum`.`id`)

here are my codes

:Subalbum model:::

var $hasOne = array('Album');

:Album model 

var $hasMany = 'Subalbum';


can any body help me?
-- 
Ganganath Hettiarachchi

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: cake model association error

2011-06-22 Thread Jeremy Burns | Class Outfit
Try this instead:

:Subalbum model:::

var $belongsTo = array('Album');

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Jun 2011, at 08:54, madusanka hettiarachchi wrote:

 HI guys,
 
 Im new to cake! I made a association between two models called Album and 
 Subalbum.
 association should be like this,
 
 Subalbum hasOne Album
 Album hasMany Subalbums
 
 bt I got error like this,
 
 1054: Unknown column 'Album.subalbum_id' in 'on clause' 
 [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
 
 SELECT `Subalbum`.`id`, `Subalbum`.`sub_album_name`, 
 `Subalbum`.`date_created`, `Subalbum`.`last_modified_date`, 
 `Subalbum`.`music_id`, `Subalbum`.`size`, `Subalbum`.`album_id`, 
 `Album`.`id`, `Album`.`album_name`, `Album`.`sub_directory`, 
 `Album`.`create_date`, `Album`.`last_modified_date`, `Album`.`music_id`, 
 `Album`.`album_category`, `Album`.`album_description`, `Album`.`user_id`, 
 `Album`.`size` FROM `subalbums` AS `Subalbum` LEFT JOIN `albums` AS `Album` 
 ON (`Album`.`subalbum_id` = `Subalbum`.`id`)  WHERE 1 = 1
 
 error occuerd due to highlighted part of the query, it should be 
 (`Album`.`subalbum_id` = `Subalbum`.`id`) 
 
 here are my codes 
 
 :Subalbum model:::
 
 var $hasOne = array('Album');
 
 :Album model 
 
 var $hasMany = 'Subalbum';
 
 
 can any body help me?
 -- 
 Ganganath Hettiarachchi
 
 -- 
 Our newest site for the community: CakePHP Video Tutorials 
 http://tv.cakephp.org 
 Check out the new CakePHP Questions site http://ask.cakephp.org and help 
 others with their CakePHP related questions.
  
  
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
 http://groups.google.com/group/cake-php

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: cake model association error

2011-06-22 Thread madusanka hettiarachchi
Hi Jeramy,

thank you very much, As u said error was there. thanks you again for saving
my time!

-- Forwarded message --
From: Jeremy Burns | Class Outfit jeremybu...@classoutfit.com
Date: Wed, Jun 22, 2011 at 1:38 PM
Subject: Re: cake model association error
To: cake-php@googlegroups.com


Try this instead:

:Subalbum model:::

var $belongsTo = array('Album');

Jeremy Burns
*Class Outfit*
*
*
jeremybu...@classoutfit.com jeremybu...@mac.com
http://www.classoutfit.com

On 22 Jun 2011, at 08:54, madusanka hettiarachchi wrote:

HI guys,

Im new to cake! I made a association between two models called Album and
Subalbum.
association should be like this,

Subalbum hasOne Album
Album hasMany Subalbums

bt I got error like this,
*
1054: Unknown column 'Album.subalbum_id' in 'on clause'
[CORE\cake\libs\model\datasources\dbo_source.php, line 684]

*SELECT `Subalbum`.`id`, `Subalbum`.`sub_album_name`,
`Subalbum`.`date_created`, `Subalbum`.`last_modified_date`,
`Subalbum`.`music_id`, `Subalbum`.`size`, `Subalbum`.`album_id`,
`Album`.`id`, `Album`.`album_name`, `Album`.`sub_directory`,
`Album`.`create_date`, `Album`.`last_modified_date`, `Album`.`music_id`,
`Album`.`album_category`, `Album`.`album_description`, `Album`.`user_id`,
`Album`.`size` FROM `subalbums` AS `Subalbum` LEFT JOIN `albums` AS `Album`
ON (`Album`.`subalbum_id` = `Subalbum`.`id`)  WHERE 1 = 1

error occuerd due to highlighted part of the query, it should be
(`Album`.`subalbum_id`
= `Subalbum`.`id`)

here are my codes

:Subalbum model:::

var $hasOne = array('Album');

:Album model 

var $hasMany = 'Subalbum';


can any body help me?
-- 
Ganganath Hettiarachchi

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php


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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php



-- 
Ganganath Hettiarachchi
Faculty of Information Technology
UOM

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Adding a count to model association

2011-02-17 Thread Rene_
Hi,

does anyone know how to add a custom count to a model?
I've tryied using 'finderQuery', and 'counterQuery', and no results..

My count query, and model looks like this:

var $hasMany = array(
'Record' = array('className' = 'Record',
'foreignKey' = 'id',
'order' = '',
'conditions' = '',
'fields' = '',
'finderQuery' = 
(
(
(
SELECT COUNT(kvcbs.id) 
AS count
FROM kvcbs
WHERE ((kvcbs.file_id = 
records.id) AND (kvcbs.kvcb_posoda 
''))
) +
(
SELECT COUNT(sins.id) 
AS count
FROM sins
WHERE ((sins.file_id = 
records.id) AND (sins.sin_posoda
 ''))
)
) +
(
SELECT COUNT(others.id) AS count
FROM others
WHERE ((others.file_id = 
records.id) AND (others.drugo_posoda 
''))
)
) AS found

)
);

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


How would one set up this model association?

2011-01-26 Thread Chillwabbitt
Hi I have three tables all linked to one lookup table like so:

+-
+
 | AUXProductOption |
+
+---
+
| id | productOptionName|
+
+---
+
|  1 | Death, Total and Permanent Disability, Tempor|
|  5 | total,
540   |
|  6 | test fixed amount
|
+
+---
+

+-
+
 | AUXProductOptionFields|
+
+---
+
| id|
name |
+
+---
+
|  1   | Test
Field|
+
+---
+

+-
+
 | AUXProductOptionFieldValue  |
+
+---
+
| id|
value  |
+
+---
+
|  1   |
1001   |
|  2   | This is rover calling back huston   |
+
+---
+

+---
+
 |
AUXProductOption_has_AUXProductOptionFields
|
+---
+
| AUXProductOption_id | AUXProductOptionFields_id |
AUXProductOptionFieldValue_id   |
+
+-
+---+
|   1|
1| 1
|
|   1|
1| 2
|
|   5|
1| 2
|
|   6|
1| 1
|
+---
+--
+---+

my models look like so :
[CODE]
class AUXProductOption extends AppModel {
var $name = 'AUXProductOption';
var $useTable = 'AUXProductOption';
var $displayField = 'productOptionName';
//The Associations below have been created with all possible keys,
those that are not needed can be removed

var $hasAndBelongsToMany = array(
'AUXProductOptionField' = array(
'className' = 'AUXProductOptionField',
'joinTable' = 
'AUXProductOption_has_AUXProductOptionFields',
'foreignKey' = 'AUXProductOptionFields_id',
'associationForeignKey' = 'AUXProductOption_id',
'unique' = true,
'conditions' = '',
'fields' = '',
'order' = '',
'limit' = '',
'offset' = '',
'finderQuery' = '',
'deleteQuery' = '',
'insertQuery' = ''
),
'AUXProductOptionFieldValue' = array(
'className' = 'AUXProductOptionFieldValue',
'joinTable' = 
'AUXProductOption_has_AUXProductOptionFields',
'foreignKey' = 'AUXProductOptionFieldValue_id',
'associationForeignKey' = 'AUXProductOption_id',
'unique' = true,
'conditions' = '',
'fields' = '',
'order' = '',
'limit' = '',
'offset' = '',
'finderQuery' = '',
'deleteQuery' = '',
'insertQuery' = ''
)
);

}

class AUXProductOptionField extends AppModel {
var $name = 'AUXProductOptionField';
var $useTable = 'AUXProductOptionFields';
var $displayField = 'name';

var $hasAndBelongsToMany = array(
'AUXProductOptionFieldValue' = array(

Re: How would one set up this model association?

2011-01-26 Thread Chillwabbitt
OK forget that here's a picture
http://i29.photobucket.com/albums/c297/Chillwabbitt/junk/Screenshot.png

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: URGENT - Help needed - Model Association

2010-12-31 Thread Karthikeyan P
Thanks @cricket and @John

@John I generated the code and then added the relationships manually .
Tried all from scratch ..and now it associates well and correctly :)

@Cricket will try both now

Thanks for the help

Karthik

On Fri, Dec 31, 2010 at 4:15 AM, John L confidentia...@gmail.com wrote:

 Since we both trust the generated code why don't you do the associations
 using the bake command also? Much simpler.

 I only mention the incorrect names as these were the names indicated in the
 first message. It matters.


 On Thu, Dec 30, 2010 at 12:03 AM, Karthikeyan P 
 pkaarthike...@gmail.comwrote:

 John

   I think the class name conventions are correct as the code is a
 generated one ..I didn't write the code.It was generated by cake bake
 command .


 * Model 'Comment' has a 'comments' table, not a 'Comments'
 table. *

 I have not defined anywhere as *Comments* Table..I have done as *comments
 * only

 I guess the problem is in the relationship type during the model
 association ? Not sure though

 Thanks
 Karthikeyan P


 On Thu, Dec 30, 2010 at 4:08 AM, john lyles confidentia...@gmail.comwrote:

 If the model names are Post and User then the table names should be
 'posts' and 'users' lowercased. The field name is 'user_id' not
 'UserId'. Model 'Comment' has a 'comments' table, not a 'Comments'
 table. You have to respect CakePHP's File and Classname conventions,
 see section 2.4.1 in the manual.

 On Dec 29, 11:19 am, pinastro pkaarthike...@gmail.com wrote:
  I have created a Blog Application using a base table as 'Posts'. Later
  Model-Associated with another table 'Users' with 'belongsTo'
  relationship like below in the MODEL
 
  var $belongsTo = array(
  'User' = array(
  'className' = 'User',
  'foreignKey' = 'user_id',
  'conditions' = '',
  'fields' = '',
  'order' = ''
  )
  );
 
  But still I am not able to store the UserId in the Posts Table ???
  What's the Problem
 
  Plus what does the following lines of code mean :: I saw the
  comments_controller.php which got generated using the BAKE command
  when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :
 
  $posts = $this-Comment-Post-find('list');
  $this-set(compact('posts'));
 
  If not above ; is there anyway I can store the UserId in the Posts
  Table using Model Associated cakePHP application ?

 Check out the new CakePHP Questions site http://cakeqs.org and help
 others with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en


  Check out the new CakePHP Questions site http://cakeqs.org and help
 others with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en


  Check out the new CakePHP Questions site http://cakeqs.org and help
 others with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: URGENT - Help needed - Model Association

2010-12-30 Thread cricket
How are you including $user_id? There are more than one approache you can take:

echo $this-Form-hidden('Post.user_id', array('value' =
$this-Session-read('Auth.User.id')));

Or you can add it to the submitted data inside the controller:

if (!empty($this-data))
{
$this-data['Post']['user_id'] = $this-Auth-user('id');

On Thu, Dec 30, 2010 at 12:03 AM, Karthikeyan P pkaarthike...@gmail.com wrote:
 John

   I think the class name conventions are correct as the code is a generated
 one ..I didn't write the code.It was generated by cake bake command .

  Model 'Comment' has a 'comments' table, not a 'Comments'
 table. 

 I have not defined anywhere as Comments Table..I have done as comments only

 I guess the problem is in the relationship type during the model association
 ? Not sure though

 Thanks
 Karthikeyan P

 On Thu, Dec 30, 2010 at 4:08 AM, john lyles confidentia...@gmail.com
 wrote:

 If the model names are Post and User then the table names should be
 'posts' and 'users' lowercased. The field name is 'user_id' not
 'UserId'. Model 'Comment' has a 'comments' table, not a 'Comments'
 table. You have to respect CakePHP's File and Classname conventions,
 see section 2.4.1 in the manual.

 On Dec 29, 11:19 am, pinastro pkaarthike...@gmail.com wrote:
  I have created a Blog Application using a base table as 'Posts'. Later
  Model-Associated with another table 'Users' with 'belongsTo'
  relationship like below in the MODEL
 
  var $belongsTo = array(
  'User' = array(
  'className' = 'User',
  'foreignKey' = 'user_id',
  'conditions' = '',
  'fields' = '',
  'order' = ''
  )
  );
 
  But still I am not able to store the UserId in the Posts Table ???
  What's the Problem
 
  Plus what does the following lines of code mean :: I saw the
  comments_controller.php which got generated using the BAKE command
  when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :
 
  $posts = $this-Comment-Post-find('list');
  $this-set(compact('posts'));
 
  If not above ; is there anyway I can store the UserId in the Posts
  Table using Model Associated cakePHP application ?

 Check out the new CakePHP Questions site http://cakeqs.org and help others
 with their CakePHP related questions.

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

 Check out the new CakePHP Questions site http://cakeqs.org and help others
 with their CakePHP related questions.

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


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: URGENT - Help needed - Model Association

2010-12-30 Thread John L
Since we both trust the generated code why don't you do the associations
using the bake command also? Much simpler.

I only mention the incorrect names as these were the names indicated in the
first message. It matters.


On Thu, Dec 30, 2010 at 12:03 AM, Karthikeyan P pkaarthike...@gmail.comwrote:

 John

   I think the class name conventions are correct as the code is a generated
 one ..I didn't write the code.It was generated by cake bake command .


 * Model 'Comment' has a 'comments' table, not a 'Comments'
 table. *

 I have not defined anywhere as *Comments* Table..I have done as *comments*only

 I guess the problem is in the relationship type during the model
 association ? Not sure though

 Thanks
 Karthikeyan P


 On Thu, Dec 30, 2010 at 4:08 AM, john lyles confidentia...@gmail.comwrote:

 If the model names are Post and User then the table names should be
 'posts' and 'users' lowercased. The field name is 'user_id' not
 'UserId'. Model 'Comment' has a 'comments' table, not a 'Comments'
 table. You have to respect CakePHP's File and Classname conventions,
 see section 2.4.1 in the manual.

 On Dec 29, 11:19 am, pinastro pkaarthike...@gmail.com wrote:
  I have created a Blog Application using a base table as 'Posts'. Later
  Model-Associated with another table 'Users' with 'belongsTo'
  relationship like below in the MODEL
 
  var $belongsTo = array(
  'User' = array(
  'className' = 'User',
  'foreignKey' = 'user_id',
  'conditions' = '',
  'fields' = '',
  'order' = ''
  )
  );
 
  But still I am not able to store the UserId in the Posts Table ???
  What's the Problem
 
  Plus what does the following lines of code mean :: I saw the
  comments_controller.php which got generated using the BAKE command
  when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :
 
  $posts = $this-Comment-Post-find('list');
  $this-set(compact('posts'));
 
  If not above ; is there anyway I can store the UserId in the Posts
  Table using Model Associated cakePHP application ?

 Check out the new CakePHP Questions site http://cakeqs.org and help
 others with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en


  Check out the new CakePHP Questions site http://cakeqs.org and help
 others with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


URGENT - Help needed - Model Association

2010-12-29 Thread pinastro
I have created a Blog Application using a base table as 'Posts'. Later
Model-Associated with another table 'Users' with 'belongsTo'
relationship like below in the MODEL

var $belongsTo = array(
'User' = array(
'className' = 'User',
'foreignKey' = 'user_id',
'conditions' = '',
'fields' = '',
'order' = ''
)
);

But still I am not able to store the UserId in the Posts Table ???
What's the Problem

Plus what does the following lines of code mean :: I saw the
comments_controller.php which got generated using the BAKE command
when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :

$posts = $this-Comment-Post-find('list');
$this-set(compact('posts'));


If not above ; is there anyway I can store the UserId in the Posts
Table using Model Associated cakePHP application ?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: URGENT - Help needed - Model Association

2010-12-29 Thread john lyles
If the model names are Post and User then the table names should be
'posts' and 'users' lowercased. The field name is 'user_id' not
'UserId'. Model 'Comment' has a 'comments' table, not a 'Comments'
table. You have to respect CakePHP's File and Classname conventions,
see section 2.4.1 in the manual.

On Dec 29, 11:19 am, pinastro pkaarthike...@gmail.com wrote:
 I have created a Blog Application using a base table as 'Posts'. Later
 Model-Associated with another table 'Users' with 'belongsTo'
 relationship like below in the MODEL

 var $belongsTo = array(
 'User' = array(
 'className' = 'User',
 'foreignKey' = 'user_id',
 'conditions' = '',
 'fields' = '',
 'order' = ''
 )
 );

 But still I am not able to store the UserId in the Posts Table ???
 What's the Problem

 Plus what does the following lines of code mean :: I saw the
 comments_controller.php which got generated using the BAKE command
 when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :

 $posts = $this-Comment-Post-find('list');
 $this-set(compact('posts'));

 If not above ; is there anyway I can store the UserId in the Posts
 Table using Model Associated cakePHP application ?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: URGENT - Help needed - Model Association

2010-12-29 Thread Karthikeyan P
John

  I think the class name conventions are correct as the code is a generated
one ..I didn't write the code.It was generated by cake bake command .

* Model 'Comment' has a 'comments' table, not a 'Comments'
table. *

I have not defined anywhere as *Comments* Table..I have done as *comments*only

I guess the problem is in the relationship type during the model association
? Not sure though

Thanks
Karthikeyan P

On Thu, Dec 30, 2010 at 4:08 AM, john lyles confidentia...@gmail.comwrote:

 If the model names are Post and User then the table names should be
 'posts' and 'users' lowercased. The field name is 'user_id' not
 'UserId'. Model 'Comment' has a 'comments' table, not a 'Comments'
 table. You have to respect CakePHP's File and Classname conventions,
 see section 2.4.1 in the manual.

 On Dec 29, 11:19 am, pinastro pkaarthike...@gmail.com wrote:
  I have created a Blog Application using a base table as 'Posts'. Later
  Model-Associated with another table 'Users' with 'belongsTo'
  relationship like below in the MODEL
 
  var $belongsTo = array(
  'User' = array(
  'className' = 'User',
  'foreignKey' = 'user_id',
  'conditions' = '',
  'fields' = '',
  'order' = ''
  )
  );
 
  But still I am not able to store the UserId in the Posts Table ???
  What's the Problem
 
  Plus what does the following lines of code mean :: I saw the
  comments_controller.php which got generated using the BAKE command
  when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :
 
  $posts = $this-Comment-Post-find('list');
  $this-set(compact('posts'));
 
  If not above ; is there anyway I can store the UserId in the Posts
  Table using Model Associated cakePHP application ?

 Check out the new CakePHP Questions site http://cakeqs.org and help others
 with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Model association, I've made it correctly???

2010-10-17 Thread Mariano C.
I'm studing model associations, I would know if i've understand it
correctly:

I have five tables: users, books, books_users, authors and types.
users, authors and types just have PK field called id.
books have PK called id and FK called author_id (ref. Authors)
books_users have PK called id and 3 FKs user_id, book_id, type_id
(respectively Ref. users, books, types).

I have create 5 model (Book, Author, User, BooksUser and Type) and
arranged the associations as:
Book belongsTo Author
Book hasMany BooksUser

Author hasMany Book

User hasMany BooksUser

BooksUser belongsTo Book, User, Type

Type belongsTo BooksUser


Is this correct???
Regards

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model association, I've made it correctly???

2010-10-17 Thread euromark
you probably meant
Type hasMany BooksUser...


On 17 Okt., 22:17, Mariano C. mariano.calan...@gmail.com wrote:
 I'm studing model associations, I would know if i've understand it
 correctly:

 I have five tables: users, books, books_users, authors and types.
 users, authors and types just have PK field called id.
 books have PK called id and FK called author_id (ref. Authors)
 books_users have PK called id and 3 FKs user_id, book_id, type_id
 (respectively Ref. users, books, types).

 I have create 5 model (Book, Author, User, BooksUser and Type) and
 arranged the associations as:
 Book belongsTo Author
 Book hasMany BooksUser

 Author hasMany Book

 User hasMany BooksUser

 BooksUser belongsTo Book, User, Type

 Type belongsTo BooksUser

 Is this correct???
 Regards

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model association problem - not getting expected array using $hasMany and $belongsTo association

2010-10-12 Thread cricket
Everything appears to be correct. Try deleting any files in
app/tmp/cache/models/ if you haven't already. And set debug to 2, both
so the models won't be cached and so you can see what queries are
being run.

On Mon, Oct 11, 2010 at 2:04 PM, Ashwani Kumar
ashwani.mail...@gmail.com wrote:
 Hi all! Today was trying to learn associations but i couldn't succeed.
 I'm getting some issue in getting associated array. I've two tables :
 authors
        - id
        - name
        - email
        - website

 books
        - id
        - isbn
        - title
        - description
        - author_id

 controllers/authors_controller.php

 ?php
        class AuthorsController extends AppController {
                var $name = 'Authors';

                function index() {
                        $this-Author-recursive = 1;
                        $authors = $this-Author-find('all');
                        $this-set('authors', $authors);
                }
        }

 controllers/books_controllers.php

 ?php
        class BooksController extends AppController {
                var $name = 'Books';

                function index() {
                        $this-Book-recursive = 1;
                        $books = $this-Book-find('all');
                        $this-set('books', $books);
                }
        }

 models/authors.php

 ?php
        class Author extends AppModel {
                var $name = 'Author';
                var $hasMany = array('Book');
        }

 models/books.php

 ?php
        class Book extends AppModel {
                var $name = 'Book';
                var $belongsTo = array('Author');
        }

 books
 id      isbn    title           description             author_id
 1       12345   book1           asdfasdfasdf                    1
 2       book2   asdfasfasdf ag as sadfas dfsdaf         1
 3       345345  dfgvsdf         gsdgsdf sdfg sdfg dfg   2

 authors

 id      name                            email                                 
           website
 1       Sams Publication        s...@samspublications.com       
 http://www.samspublications.com
 2       Test Author             auth...@testauthors.com          
 http://www.author1.com




 When i try to run print 'pre'; print_r($authors), i get following
 array :

 Array
 (
    [0] = Array
        (
            [Author] = Array
                (
                    [id] = 1
                    [name] = Sams Publication
                    [email] = s...@samspublications.com
                    [website] = http://www.samspublications.com
                )

        )

    [1] = Array
        (
            [Author] = Array
                (
                    [id] = 2
                    [name] = Test Author
                    [email] = auth...@testauthors.com
                    [website] = http://www.author1.com
                )

        )

 )

 So, my problem is that there's no Book array in above array. Please
 help... Thanks in advance.

 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.

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


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Model association problem - not getting expected array using $hasMany and $belongsTo association

2010-10-11 Thread Ashwani Kumar
Hi all! Today was trying to learn associations but i couldn't succeed.
I'm getting some issue in getting associated array. I've two tables :
authors
- id
- name
- email
- website

books
- id
- isbn
- title
- description
- author_id

controllers/authors_controller.php

?php
class AuthorsController extends AppController {
var $name = 'Authors';

function index() {
$this-Author-recursive = 1;
$authors = $this-Author-find('all');
$this-set('authors', $authors);
}
}

controllers/books_controllers.php

?php
class BooksController extends AppController {
var $name = 'Books';

function index() {
$this-Book-recursive = 1;
$books = $this-Book-find('all');
$this-set('books', $books);
}
}

models/authors.php

?php
class Author extends AppModel {
var $name = 'Author';
var $hasMany = array('Book');
}

models/books.php

?php
class Book extends AppModel {
var $name = 'Book';
var $belongsTo = array('Author');
}

books
id  isbntitle   description author_id
1   12345   book1   asdfasdfasdf1
2   book2   asdfasfasdf ag as sadfas dfsdaf 1
3   345345  dfgvsdf gsdgsdf sdfg sdfg dfg   2

authors

id  nameemail   
website
1   Sams Publications...@samspublications.com   
http://www.samspublications.com
2   Test Author auth...@testauthors.com  
http://www.author1.com




When i try to run print 'pre'; print_r($authors), i get following
array :

Array
(
[0] = Array
(
[Author] = Array
(
[id] = 1
[name] = Sams Publication
[email] = s...@samspublications.com
[website] = http://www.samspublications.com
)

)

[1] = Array
(
[Author] = Array
(
[id] = 2
[name] = Test Author
[email] = auth...@testauthors.com
[website] = http://www.author1.com
)

)

)

So, my problem is that there's no Book array in above array. Please
help... Thanks in advance.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


How to attach model association belongsTo on the fly?

2010-04-23 Thread Ziki
How to attach model association belongsTo on the fly? I ama developing
plugin so I need that, to attach somewhere in my component.

Help please

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


general model association/SQL question: linking one table to many others

2010-04-14 Thread Vadim Frolov
Hi!

I have a table phrases. It has fields id as INT and value as TEXT. This
table is used to store different phrases or sentences. Now I want to
describe a car with a model name and description. I want both these values
to reference phrases table. In my opinion Car hasOne name and hasOne
description. But it seems that in SQL/CakePHP notation it is not true. To
make hasOne in Cake I would need to add field car_id in my phrases table.
Then if I introduce the table cities also with name and description, I would
need additional rows in phrases table...

I think that I can create additional tables cars_names and cars_descriptions
and connect them through HABTM association with cards and phrases. But I
find inconvenient to create additional table for every phrase field  I want
to add.

Maybe someone knows what can I do in this situation?

Regards,
Vadim.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using remove me as the subject.


Re: general model association/SQL question: linking one table to many others

2010-04-14 Thread cricket
On Apr 14, 12:34 pm, Vadim Frolov fra...@gmail.com wrote:
 Hi!

 I have a table phrases. It has fields id as INT and value as TEXT. This
 table is used to store different phrases or sentences. Now I want to
 describe a car with a model name and description. I want both these values
 to reference phrases table. In my opinion Car hasOne name and hasOne
 description. But it seems that in SQL/CakePHP notation it is not true. To
 make hasOne in Cake I would need to add field car_id in my phrases table.
 Then if I introduce the table cities also with name and description, I would
 need additional rows in phrases table...

 I think that I can create additional tables cars_names and cars_descriptions
 and connect them through HABTM association with cards and phrases. But I
 find inconvenient to create additional table for every phrase field  I want
 to add.

This is a bit backwards but I think it would work.

Car model:

var $belongsTo = array(
'CarName' = array(
'className' = 'Phrase',
'foreignKey' = 'name_id'
),
'CarDescription' = array(
'className' = 'Phrase',
'foreignKey' = 'description_id'
)
);

The scenario you describe seems a little messy though. Maybe there's a
better approach. Does this concern translations?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using remove me as the subject.


Re: general model association/SQL question: linking one table to many others

2010-04-14 Thread Vadim Frolov
yes, I do so because I want to translate my phrases. I would use CakePHP to
translate interface, but also want my actual data to be in several
languages. Seems that creating additional table for each field is the only
way to go =(

Regards,
Vadim.

On 15 April 2010 04:44, cricket zijn.digi...@gmail.com wrote:


 This is a bit backwards but I think it would work.

 Car model:

 var $belongsTo = array(
'CarName' = array(
'className' = 'Phrase',
'foreignKey' = 'name_id'
),
'CarDescription' = array(
'className' = 'Phrase',
'foreignKey' = 'description_id'
)
 );

 The scenario you describe seems a little messy though. Maybe there's a
 better approach. Does this concern translations?


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using remove me as the subject.


Re: Better way to handle this model association

2010-03-23 Thread WebbedIT
If there is no validation I would probably create my data array so you
have one Review with Many ServiceTypes, each with its many Criterias.

In the controller I would then save the Review before looping through
each ServiceType using saveAll to save ServiceType and it's many
Criteria.

This should negate the need for massaging the data array as I don't
think you can call one saveAll to save all of this in one go.

Hope this gives you another angle to consider, and form looks good by
the way :P

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Better way to handle this model association

2010-03-22 Thread jwerd
Paul,

First off, Thanks for taking a look.

I guess I am just confused on how I can go about the associations,
since my ratings table is storing specific based on the
editorial_review_id's service_type_id, if that makes sense.

Essentially, someone creates a review, and they drill down with the
rating criteria of each service, since services will having different
ratings.  So an example would be:

Parent: Editorial Review
Child: Service Type: Hosted
Sub Child: Rating Criteria 1
Sub Child: Rating Criteria 2
Sub Child: Rating Criteria 3
Sub Child: Rating Criteria 4
Sub Child: Rating Criteria 5
Sub Child: Rating Criteria 6
Sub Child: Rating Criteria 7
Sub Child: Rating Criteria 8

Child: Service Type: VPS
Sub Child: Rating Criteria 1
Sub Child: Rating Criteria 2
Sub Child: Rating Criteria 3
Sub Child: Rating Criteria 4
Sub Child: Rating Criteria 5
Sub Child: Rating Criteria 6
Sub Child: Rating Criteria 7
Sub Child: Rating Criteria 8

The reason I'm doing this this way is I want to make this system a bit
more dynamic, in the sense that a publisher could add more rating
criterias later on without a bunch of code changes, etc.

So, my reason for massging is, I do not know how I can go about saving
this later in a way that cake understands it.  I have to set up a
bunch of hidden id's just so I can bring this data in to save it, eg:
?php $i = 0; ?
?php $k = 0; ?

div style=clear:both;
?php foreach($this-viewVars['serviceTypes'] as $key = $val): ?
div id=service_type_?=$key? style=display: none;
position:relative; padding: 5px; background: #ddd; float:left; margin-
right:4px;
h3
?php echo $form-label($val); ?
/h3
?php $j = 1;?
?php foreach($ratingTypes as $key2 = $val2): ?
br /
?php if(!empty($this-data['Rating'][$key][$j]['id'])): ?
?php echo $form-hidden('', array('name' = 'data[Rating]['.$key.']
['.$j.'][id]', 'value'=@$this-data['Rating'][$key][$j]['id'])); ?
?php endif; ?
?php echo $form-hidden('EditorialReviewId', array('name' =
'data[Rating]['.$key.']['.$j.'][editorial_reviews_id]', 'value'=@
$this-data['EditorialReview']['id'])); ?
?php echo $form-hidden('ServiceTypeId', array('name' =
'data[Rating]['.$key.']['.$j.'][service_types_id]', 'value'=@$key)); ?

?php echo $form-hidden('RatingTypeId', array('name' = 'data[Rating]
['.$key.']['.$j.'][rating_types_id]', 'value'=@$key2)); ?
?php
$select = (isset($this-data['Rating'][$key][$j]['rating'])) ? 
$this-
data['Rating'][$key][$j]['rating'] : 1;
?
div style=padding: 5px; margin-bottom: 0px; background: #ccc;
display: inline; width:220px; float:left;
?php
echo $form-label($val2);
?
/div
div style=margin-bottom: 0px; padding: 5px; display: inline;
?php
echo $form-select('', array('1'='1 - Very
Poor','2'='2','3'='3','4'='4','5'='5 - Average', '6'='6',
'7'='7', '8'='8', '9'='9', '10'='10 - Excellent'), @$select,
array('style'='position:relative; top:2px;','name'= 'data[Rating]['.
$key.']['.$j.'][rating]'), false);
unset($select);
?
/div
div style=clear:both;/div
?php ++$j; ?
?php ++$k; ?
?php endforeach; ?

There has to be an easier way than this convoluted system.  There is
also a bug with this, doing it this way, I have to have the record
created so I can associate the editorial_review_id with the ratings.

TIA

On Mar 21, 1:45 am, WebbedIT p...@webbedit.co.uk wrote:
 I'm slightly confused, why do you have to massage the data array?
 What part of your save process is not working, I'm guessing your
 saying it is not autosaving the HABTM data.

 If so, what does your submitted data array and save action look like?

 HTH

 Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Better way to handle this model association

2010-03-22 Thread WebbedIT
OK, so you're trying to save hasMany records each with their own
HABTM, there is no automagic that will do that for you hence why
you've had to try and come up with your own solution.

Are you sure it's not easier to save just one review/serviceType combo
at a time?  By trying to do lots in one go you're also going to have
problems validating your data and displaying errors etc.  You could
create an array of data arrays and loop through them validating and
saving, but even that is a minefield as at what point of validation
fails to you return and what do you do with those records that were
saved.

Any chance of seeing one of your forms in action (I have great
difficulty looking at table schemas and php/html and visualising how
the end product looks), it may give me a better idea of what you're
trying to achieve.

HTH

Paul.

On Mar 22, 6:48 am, jwerd lamerh...@gmail.com wrote:
 Paul,

 First off, Thanks for taking a look.

 I guess I am just confused on how I can go about the associations,
 since my ratings table is storing specific based on the
 editorial_review_id's service_type_id, if that makes sense.

 Essentially, someone creates a review, and they drill down with the
 rating criteria of each service, since services will having different
 ratings.  So an example would be:

 Parent: Editorial Review
 Child: Service Type: Hosted
 Sub Child: Rating Criteria 1
 Sub Child: Rating Criteria 2
 Sub Child: Rating Criteria 3
 Sub Child: Rating Criteria 4
 Sub Child: Rating Criteria 5
 Sub Child: Rating Criteria 6
 Sub Child: Rating Criteria 7
 Sub Child: Rating Criteria 8

 Child: Service Type: VPS
 Sub Child: Rating Criteria 1
 Sub Child: Rating Criteria 2
 Sub Child: Rating Criteria 3
 Sub Child: Rating Criteria 4
 Sub Child: Rating Criteria 5
 Sub Child: Rating Criteria 6
 Sub Child: Rating Criteria 7
 Sub Child: Rating Criteria 8

 The reason I'm doing this this way is I want to make this system a bit
 more dynamic, in the sense that a publisher could add more rating
 criterias later on without a bunch of code changes, etc.

 So, my reason for massging is, I do not know how I can go about saving
 this later in a way that cake understands it.  I have to set up a
 bunch of hidden id's just so I can bring this data in to save it, eg:
 ?php $i = 0; ?
 ?php $k = 0; ?

 div style=clear:both;
 ?php foreach($this-viewVars['serviceTypes'] as $key = $val): ?
 div id=service_type_?=$key? style=display: none;
 position:relative; padding: 5px; background: #ddd; float:left; margin-
 right:4px;
         h3
         ?php echo $form-label($val); ?
         /h3
         ?php $j = 1;?
         ?php foreach($ratingTypes as $key2 = $val2): ?
         br /
         ?php if(!empty($this-data['Rating'][$key][$j]['id'])): ?
         ?php echo $form-hidden('', array('name' = 'data[Rating]['.$key.']
 ['.$j.'][id]', 'value'=@$this-data['Rating'][$key][$j]['id'])); ?
         ?php endif; ?
         ?php echo $form-hidden('EditorialReviewId', array('name' =
 'data[Rating]['.$key.']['.$j.'][editorial_reviews_id]', 'value'=@
 $this-data['EditorialReview']['id'])); ?
         ?php echo $form-hidden('ServiceTypeId', array('name' =
 'data[Rating]['.$key.']['.$j.'][service_types_id]', 'value'=@$key)); ?

         ?php echo $form-hidden('RatingTypeId', array('name' = 'data[Rating]
 ['.$key.']['.$j.'][rating_types_id]', 'value'=@$key2)); ?
         ?php
                 $select = (isset($this-data['Rating'][$key][$j]['rating'])) 
 ? $this-data['Rating'][$key][$j]['rating'] : 1;

         ?
         div style=padding: 5px; margin-bottom: 0px; background: #ccc;
 display: inline; width:220px; float:left;
         ?php
                 echo $form-label($val2);
         ?
         /div
         div style=margin-bottom: 0px; padding: 5px; display: inline;
         ?php
                 echo $form-select('', array('1'='1 - Very
 Poor','2'='2','3'='3','4'='4','5'='5 - Average', '6'='6',
 '7'='7', '8'='8', '9'='9', '10'='10 - Excellent'), @$select,
 array('style'='position:relative; top:2px;','name'= 'data[Rating]['.
 $key.']['.$j.'][rating]'), false);
                 unset($select);
         ?
         /div
         div style=clear:both;/div
         ?php ++$j; ?
         ?php ++$k; ?
         ?php endforeach; ?

 There has to be an easier way than this convoluted system.  There is
 also a bug with this, doing it this way, I have to have the record
 created so I can associate the editorial_review_id with the ratings.

 TIA

 On Mar 21, 1:45 am, WebbedIT p...@webbedit.co.uk wrote:

  I'm slightly confused, why do you have to massage the data array?
  What part of your save process is not working, I'm guessing your
  saying it is not autosaving the HABTM data.

  If so, what does your submitted data array and save action look like?

  HTH

  Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To 

Re: Better way to handle this model association

2010-03-22 Thread jwerd
Paul,

This is how the end product looks:
http://farm5.static.flickr.com/4039/4453982845_d2908b4527_o.png

Basically, when a user selects a service type (checks it) it spawns a
box below, with the rating criterias, etc (I handle that with jquery
and all that jazz, of no importance ot this though).  Anyways,
everything is good to go, it's just, I was wondering if there is a
better way of doing this.  If you notice, there really isn't much
validation to go on, as the user _HAS TO_ rate if select a service
type to rate, etc...

So, whatcha think?  Any better way of handling this?

On Mar 22, 2:19 am, WebbedIT p...@webbedit.co.uk wrote:
 OK, so you're trying to save hasMany records each with their own
 HABTM, there is no automagic that will do that for you hence why
 you've had to try and come up with your own solution.

 Are you sure it's not easier to save just one review/serviceType combo
 at a time?  By trying to do lots in one go you're also going to have
 problems validating your data and displaying errors etc.  You could
 create an array of data arrays and loop through them validating and
 saving, but even that is a minefield as at what point of validation
 fails to you return and what do you do with those records that were
 saved.

 Any chance of seeing one of your forms in action (I have great
 difficulty looking at table schemas and php/html and visualising how
 the end product looks), it may give me a better idea of what you're
 trying to achieve.

 HTH

 Paul.

 On Mar 22, 6:48 am, jwerd lamerh...@gmail.com wrote:

  Paul,

  First off, Thanks for taking a look.

  I guess I am just confused on how I can go about the associations,
  since my ratings table is storing specific based on the
  editorial_review_id's service_type_id, if that makes sense.

  Essentially, someone creates a review, and they drill down with the
  rating criteria of each service, since services will having different
  ratings.  So an example would be:

  Parent: Editorial Review
  Child: Service Type: Hosted
  Sub Child: Rating Criteria 1
  Sub Child: Rating Criteria 2
  Sub Child: Rating Criteria 3
  Sub Child: Rating Criteria 4
  Sub Child: Rating Criteria 5
  Sub Child: Rating Criteria 6
  Sub Child: Rating Criteria 7
  Sub Child: Rating Criteria 8

  Child: Service Type: VPS
  Sub Child: Rating Criteria 1
  Sub Child: Rating Criteria 2
  Sub Child: Rating Criteria 3
  Sub Child: Rating Criteria 4
  Sub Child: Rating Criteria 5
  Sub Child: Rating Criteria 6
  Sub Child: Rating Criteria 7
  Sub Child: Rating Criteria 8

  The reason I'm doing this this way is I want to make this system a bit
  more dynamic, in the sense that a publisher could add more rating
  criterias later on without a bunch of code changes, etc.

  So, my reason for massging is, I do not know how I can go about saving
  this later in a way that cake understands it.  I have to set up a
  bunch of hidden id's just so I can bring this data in to save it, eg:
  ?php $i = 0; ?
  ?php $k = 0; ?

  div style=clear:both;
  ?php foreach($this-viewVars['serviceTypes'] as $key = $val): ?
  div id=service_type_?=$key? style=display: none;
  position:relative; padding: 5px; background: #ddd; float:left; margin-
  right:4px;
          h3
          ?php echo $form-label($val); ?
          /h3
          ?php $j = 1;?
          ?php foreach($ratingTypes as $key2 = $val2): ?
          br /
          ?php if(!empty($this-data['Rating'][$key][$j]['id'])): ?
          ?php echo $form-hidden('', array('name' = 'data[Rating]['.$key.']
  ['.$j.'][id]', 'value'=@$this-data['Rating'][$key][$j]['id'])); ?
          ?php endif; ?
          ?php echo $form-hidden('EditorialReviewId', array('name' =
  'data[Rating]['.$key.']['.$j.'][editorial_reviews_id]', 'value'=@
  $this-data['EditorialReview']['id'])); ?
          ?php echo $form-hidden('ServiceTypeId', array('name' =
  'data[Rating]['.$key.']['.$j.'][service_types_id]', 'value'=@$key)); ?

          ?php echo $form-hidden('RatingTypeId', array('name' = 
  'data[Rating]
  ['.$key.']['.$j.'][rating_types_id]', 'value'=@$key2)); ?
          ?php
                  $select = 
  (isset($this-data['Rating'][$key][$j]['rating'])) ? 
  $this-data['Rating'][$key][$j]['rating'] : 1;

          ?
          div style=padding: 5px; margin-bottom: 0px; background: #ccc;
  display: inline; width:220px; float:left;
          ?php
                  echo $form-label($val2);
          ?
          /div
          div style=margin-bottom: 0px; padding: 5px; display: inline;
          ?php
                  echo $form-select('', array('1'='1 - Very
  Poor','2'='2','3'='3','4'='4','5'='5 - Average', '6'='6',
  '7'='7', '8'='8', '9'='9', '10'='10 - Excellent'), @$select,
  array('style'='position:relative; top:2px;','name'= 'data[Rating]['.
  $key.']['.$j.'][rating]'), false);
                  unset($select);
          ?
          /div
          div style=clear:both;/div
          ?php ++$j; ?
          ?php ++$k; ?
          ?php endforeach; ?

  

Re: Better way to handle this model association

2010-03-21 Thread WebbedIT
I'm slightly confused, why do you have to massage the data array?
What part of your save process is not working, I'm guessing your
saying it is not autosaving the HABTM data.

If so, what does your submitted data array and save action look like?

HTH

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Better way to handle this model association

2010-03-20 Thread jwerd
Ok, I'm going to try to make this quick.  This _works_ but I think
there is a better way to do it.

Tables:

CREATE TABLE `ratings` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `rating_types_id` tinyint(3) default NULL,
  `editorial_reviews_id` int(11) default NULL,
  `service_types_id` int(11) default NULL,
  `rating` tinyint(2) unsigned NOT NULL default '0',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=403 DEFAULT CHARSET=latin1

CREATE TABLE `rating_types` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `published` tinyint(1) default NULL,
  `created` datetime default NULL,
  `updated` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1

CREATE TABLE `service_types` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) default NULL,
  `published` tinyint(1) default NULL,
  `created` datetime default NULL,
  `updated` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1

CREATE TABLE `editorial_reviews` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `review` text,
  `published` tinyint(1) default NULL,
  `created` datetime default NULL,
  `updated` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1

CREATE TABLE `editorial_reviews_service_types` (
  `editorial_reviews_id` int(11) default NULL,
  `service_types_id` tinyint(2) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
=

editorial_reviews habtm service_types

Anyways, so the main focus point is the ratings table.  Essentially,
I want to store the ratings based on a specific editorial and service
type, hence the reason the columns are both present in that table.

The problem is, I have to do a little trickery here, where I have to
write some beforeSave logic to actually insert the rows, and I just
think Cake has an easier way to handle something like this.

Take for instance from the editorial_review.php model:
function beforeSave()
{
if(count($this-data['ServiceType']['ServiceType'])  0  count(@
$this-data['Rating'])  0)) {

// Mapping ServiceTypes
$service_types = array();
if(isset($this-data['ServiceType']['ServiceType'][0])) 
{
foreach(@$this-data['ServiceType']['ServiceType'] 
as $key=
$val) {
$service_types[$val] = $val;
}
}



foreach($this-data['Rating'] as $step) {
foreach($step as $key = $val) {
if(!empty($val['rating'])) {
// Check if service_type is checked

if(@$service_typ...@$val['service_types_id']] == @
$val['service_types_id']) {
$data_array['Rating'] = array(
  'id'  
 = @
$val['id'],

  'editorial_reviews_id' =
$val['editorial_reviews_id'],

  'service_types_id' =
$val['service_types_id'],

  'rating_types_id'  =
$val['rating_types_id'],

  'rating'   = $val['rating']);
//pr($data_array);

$this-Rating-save($data_array);
} else {
// Play clean-up
$this-Rating-
deleteAll(array('Rating.editorial_reviews_id' =
$val['editorial_reviews_id'], 'Rating.service_types_id' =
$val['service_types_id']));
}
}
}
}
unset($this-data['Rating']);
  }
}
return $this-data;
}

(sorry for the mess, I feel this is more of a hack than anything...

Please help me figure out a better way to handle this, to be more
reusable, I guess is what I'm saying?

Thanks,
Jake

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 

Model association through user_id

2010-03-17 Thread abocanegra
I am trying to learn more about associating through models. My current
issue is that I am attempting to design the post add function that I
created following the tutorial so that I can select the user by
username rather than user_id. I want to have the value of the drop
down be user_id and the option be username. I have changed the add
function in controller to find('all') but that only gives me
everything in the users database. I have repeatedly failed to be able
to isolate the username from this.  Below is some of the code I have
been playing with.

add view
?php
echo $this-Form-input('user_id');
echo $this-Form-input('title');
echo $this-Form-input('body');
?

add function from controller

 function add() {
if (!empty($this-data)) {
$this-Post-create();
if ($this-Post-save($this-data)) {
$this-Session-
setFlash(sprintf(__('The %s has been saved', true), 'post'));
$this-redirect(array('action' =
'index'));
} else {
$this-Session-
setFlash(sprintf(__('The %s could not be saved. Please, try again.',
true), 'post'));
}
}
$users = $this-Post-User-find('list');
$this-set(compact('users'));
}

Belongsto from Model

var $belongsTo = array(
'User' = array(
'className' = 'User',
'foreignKey' = 'user_id',
'conditions' = '',
'fields' = '',
'order' = ''
)
);

Any advice for a clean way to pull data from the Users table from
within the Posts add view would be appreciated.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model association through user_id

2010-03-17 Thread cricket
In User model:

var $displayField = 'username';

Then find('list') will return an array as id = username

On Mar 17, 8:50 pm, abocanegra aaronbocane...@gmail.com wrote:
 I am trying to learn more about associating through models. My current
 issue is that I am attempting to design the post add function that I
 created following the tutorial so that I can select the user by
 username rather than user_id. I want to have the value of the drop
 down be user_id and the option be username. I have changed the add
 function in controller to find('all') but that only gives me
 everything in the users database. I have repeatedly failed to be able
 to isolate the username from this.  Below is some of the code I have
 been playing with.

 add view
 ?php
                 echo $this-Form-input('user_id');
                 echo $this-Form-input('title');
                 echo $this-Form-input('body');
         ?

 add function from controller

  function add() {
                 if (!empty($this-data)) {
                         $this-Post-create();
                         if ($this-Post-save($this-data)) {
                                 $this-Session-setFlash(sprintf(__('The %s 
 has been saved', true), 'post'));

                                 $this-redirect(array('action' =
 'index'));
                         } else {
                                 $this-Session-setFlash(sprintf(__('The %s 
 could not be saved. Please, try again.',

 true), 'post'));
                         }
                 }
                 $users = $this-Post-User-find('list');
                 $this-set(compact('users'));
         }

 Belongsto from Model

         var $belongsTo = array(
                 'User' = array(
                         'className' = 'User',
                         'foreignKey' = 'user_id',
                         'conditions' = '',
                         'fields' = '',
                         'order' = ''
                 )
         );

 Any advice for a clean way to pull data from the Users table from
 within the Posts add view would be appreciated.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model association through user_id

2010-03-17 Thread abocanegra
Thank you for the response. I was able to get it working finally by
the following code int he postscontroller under the add function.

$users = $this-Post-User-find('list', array('fields' =
array('User.username')));
$this-set(compact('users'));

Thanks

On Mar 17, 7:27 pm, cricket zijn.digi...@gmail.com wrote:
 In User model:

 var $displayField = 'username';

 Then find('list') will return an array as id = username

 On Mar 17, 8:50 pm,abocanegraaaronbocane...@gmail.com wrote:

  I am trying to learn more about associating through models. My current
  issue is that I am attempting to design the post add function that I
  created following the tutorial so that I can select the user by
  username rather than user_id. I want to have the value of the drop
  down be user_id and the option be username. I have changed the add
  function in controller to find('all') but that only gives me
  everything in the users database. I have repeatedly failed to be able
  to isolate the username from this.  Below is some of the code I have
  been playing with.

  add view
  ?php
                  echo $this-Form-input('user_id');
                  echo $this-Form-input('title');
                  echo $this-Form-input('body');
          ?

  add function from controller

   function add() {
                  if (!empty($this-data)) {
                          $this-Post-create();
                          if ($this-Post-save($this-data)) {
                                  $this-Session-setFlash(sprintf(__('The %s 
  has been saved', true), 'post'));

                                  $this-redirect(array('action' =
  'index'));
                          } else {
                                  $this-Session-setFlash(sprintf(__('The %s 
  could not be saved. Please, try again.',

  true), 'post'));
                          }
                  }
                  $users = $this-Post-User-find('list');
                  $this-set(compact('users'));
          }

  Belongsto from Model

          var $belongsTo = array(
                  'User' = array(
                          'className' = 'User',
                          'foreignKey' = 'user_id',
                          'conditions' = '',
                          'fields' = '',
                          'order' = ''
                  )
          );

  Any advice for a clean way to pull data from the Users table from
  within the Posts add view would be appreciated.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Model Association 'chain'

2010-02-24 Thread p_W
I have 4 models, associated like this:

Model_1 has_many Model_2
Model_2 belongs_to Model_1

Model_2 has_many Model_3
Model_3 belongs_to Model_2

Model_3 has_many Model_4
Model_4 belongs_to Model_3

In my controller, when I call `$my_var = $this-Model_1-find('all')`
the results have Model_1 and Model_2 in them, but I would like it to
recurse down through the whole chain...any thoughts?  Should I just do
it manually in a model function?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model Association 'chain'

2010-02-24 Thread John Andersen
Take a look in the CakePHP manual at the Containable behaviour, which
will give you the possibility to specify how deep you want to go in
your relationships when retrieving your data.
http://book.cakephp.org/view/474/Containable

Also it will make your life easier :)
Enjoy,
   John

On Feb 24, 4:32 pm, p_W paulwoolcoc...@gmail.com wrote:
 I have 4 models, associated like this:

 Model_1 has_many Model_2
 Model_2 belongs_to Model_1

 Model_2 has_many Model_3
 Model_3 belongs_to Model_2

 Model_3 has_many Model_4
 Model_4 belongs_to Model_3

 In my controller, when I call `$my_var = $this-Model_1-find('all')`
 the results have Model_1 and Model_2 in them, but I would like it to
 recurse down through the whole chain...any thoughts?  Should I just do
 it manually in a model function?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model Association 'chain'

2010-02-24 Thread WebbedIT
In the case of viewing a record, Containable is very much your
friend.  Saves you so much time.

If paginating deep associations, espcially if you want a condition on
model 3 or 4, then you need to get your head around ad-hoc (forced)
joins.

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

Teknoids blog is a must read if you are to get your head around
forcing joins, and you will eventually need his advice on HABTM too,
saved me edless hours of pain.

http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/

HTH

Paul.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Problem with Model Association

2009-10-07 Thread Raman

Yes, it was newspost.php.

On Oct 6, 9:10 pm, brian bally.z...@gmail.com wrote:
 That shouldn't be an issue. What was the file name? If it wasn't
 news_post.php that would do it.



 On Tue, Oct 6, 2009 at 3:01 PM, Raman rlali...@gmail.com wrote:

  Thanks brian, tried that, but it didn't work. I found the solution
  though. I'm using CakePHP version 1.3, so this might be a bug I really
  don't know.

  The problem was the capitilization of the 'P' in News'P'ost. I changed
  the model's names, filenames, etc. to just News and voila, it works!

  On Oct 6, 2:15 pm, brian bally.z...@gmail.com wrote:
  In Comment.php, add var $belongsTo = array('NewsPost');

  On Tue, Oct 6, 2009 at 1:02 PM, Raman rlali...@gmail.com wrote:

   Hello,

   Im very new to CakePHP and have just started to learn Model
   Association. If I make any errors in the google group, please excuse
   me this is my first time on any google group.

   I have 2 databases:

   -news_posts
      -id
      -title
      -body

   -comments
      -id
      -body
      -newspost_id

   Here are the AppModel classes associated with them:

   // app/models/newspost.php
   class NewsPost extends AppModel {
      var $name = 'NewsPost';
      var $hasMany = 'Comment';
   }

   // app/models/comment.php
   class Comment extends AppModel {
      var $name = 'Comment';
   }

   The problem is when i call $this-NewsPost-find('all'); from a
   controller that var $uses = 'NewsPost';, I get this array:

   Array
   (
      [0] = Array
          (
              [NewsPost] = Array
                  (
                      [id] = 10
                      [Title] = Cool, This works! LOL
                      [Body] = Wow, this really works! OMG LOL OMG
   EDITING WORKS FINE
                      [Time] = 1254685359
                  )

          )

   )

   As you can see, there is no [Comment] array in the sub-array [0].

   Here is the data for my tables:

   news_posts:

     id   |         title       |        body       |
     10  |   News Title   |   News Body   |

   comments:

     id   |            body          |       newspost_id       |
     1    |   Comment Body   |             10                |

   Any help would be greatly appreciated.

   Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Problem with Model Association

2009-10-06 Thread Raman

Hello,

Im very new to CakePHP and have just started to learn Model
Association. If I make any errors in the google group, please excuse
me this is my first time on any google group.

I have 2 databases:

-news_posts
-id
-title
-body

-comments
-id
-body
-newspost_id

Here are the AppModel classes associated with them:

// app/models/newspost.php
class NewsPost extends AppModel {
var $name = 'NewsPost';
var $hasMany = 'Comment';
}

// app/models/comment.php
class Comment extends AppModel {
var $name = 'Comment';
}

The problem is when i call $this-NewsPost-find('all'); from a
controller that var $uses = 'NewsPost';, I get this array:

Array
(
[0] = Array
(
[NewsPost] = Array
(
[id] = 10
[Title] = Cool, This works! LOL
[Body] = Wow, this really works! OMG LOL OMG
EDITING WORKS FINE
[Time] = 1254685359
)

)

)

As you can see, there is no [Comment] array in the sub-array [0].

Here is the data for my tables:

news_posts:

   id   | title   |body   |
   10  |   News Title   |   News Body   |

comments:

   id   |body  |   newspost_id   |
   1|   Comment Body   | 10|

Any help would be greatly appreciated.

Thanks.

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



Re: Problem with Model Association

2009-10-06 Thread brian

In Comment.php, add var $belongsTo = array('NewsPost');

On Tue, Oct 6, 2009 at 1:02 PM, Raman rlali...@gmail.com wrote:

 Hello,

 Im very new to CakePHP and have just started to learn Model
 Association. If I make any errors in the google group, please excuse
 me this is my first time on any google group.

 I have 2 databases:

 -news_posts
    -id
    -title
    -body

 -comments
    -id
    -body
    -newspost_id

 Here are the AppModel classes associated with them:

 // app/models/newspost.php
 class NewsPost extends AppModel {
    var $name = 'NewsPost';
    var $hasMany = 'Comment';
 }

 // app/models/comment.php
 class Comment extends AppModel {
    var $name = 'Comment';
 }

 The problem is when i call $this-NewsPost-find('all'); from a
 controller that var $uses = 'NewsPost';, I get this array:

 Array
 (
    [0] = Array
        (
            [NewsPost] = Array
                (
                    [id] = 10
                    [Title] = Cool, This works! LOL
                    [Body] = Wow, this really works! OMG LOL OMG
 EDITING WORKS FINE
                    [Time] = 1254685359
                )

        )

 )

 As you can see, there is no [Comment] array in the sub-array [0].

 Here is the data for my tables:

 news_posts:

   id   |         title       |        body       |
   10  |   News Title   |   News Body   |

 comments:

   id   |            body          |       newspost_id       |
   1    |   Comment Body   |             10                |

 Any help would be greatly appreciated.

 Thanks.

 


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



Re: Problem with Model Association

2009-10-06 Thread Raman

Thanks brian, tried that, but it didn't work. I found the solution
though. I'm using CakePHP version 1.3, so this might be a bug I really
don't know.

The problem was the capitilization of the 'P' in News'P'ost. I changed
the model's names, filenames, etc. to just News and voila, it works!

On Oct 6, 2:15 pm, brian bally.z...@gmail.com wrote:
 In Comment.php, add var $belongsTo = array('NewsPost');



 On Tue, Oct 6, 2009 at 1:02 PM, Raman rlali...@gmail.com wrote:

  Hello,

  Im very new to CakePHP and have just started to learn Model
  Association. If I make any errors in the google group, please excuse
  me this is my first time on any google group.

  I have 2 databases:

  -news_posts
     -id
     -title
     -body

  -comments
     -id
     -body
     -newspost_id

  Here are the AppModel classes associated with them:

  // app/models/newspost.php
  class NewsPost extends AppModel {
     var $name = 'NewsPost';
     var $hasMany = 'Comment';
  }

  // app/models/comment.php
  class Comment extends AppModel {
     var $name = 'Comment';
  }

  The problem is when i call $this-NewsPost-find('all'); from a
  controller that var $uses = 'NewsPost';, I get this array:

  Array
  (
     [0] = Array
         (
             [NewsPost] = Array
                 (
                     [id] = 10
                     [Title] = Cool, This works! LOL
                     [Body] = Wow, this really works! OMG LOL OMG
  EDITING WORKS FINE
                     [Time] = 1254685359
                 )

         )

  )

  As you can see, there is no [Comment] array in the sub-array [0].

  Here is the data for my tables:

  news_posts:

    id   |         title       |        body       |
    10  |   News Title   |   News Body   |

  comments:

    id   |            body          |       newspost_id       |
    1    |   Comment Body   |             10                |

  Any help would be greatly appreciated.

  Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem with Model Association

2009-10-06 Thread brian

That shouldn't be an issue. What was the file name? If it wasn't
news_post.php that would do it.

On Tue, Oct 6, 2009 at 3:01 PM, Raman rlali...@gmail.com wrote:

 Thanks brian, tried that, but it didn't work. I found the solution
 though. I'm using CakePHP version 1.3, so this might be a bug I really
 don't know.

 The problem was the capitilization of the 'P' in News'P'ost. I changed
 the model's names, filenames, etc. to just News and voila, it works!

 On Oct 6, 2:15 pm, brian bally.z...@gmail.com wrote:
 In Comment.php, add var $belongsTo = array('NewsPost');



 On Tue, Oct 6, 2009 at 1:02 PM, Raman rlali...@gmail.com wrote:

  Hello,

  Im very new to CakePHP and have just started to learn Model
  Association. If I make any errors in the google group, please excuse
  me this is my first time on any google group.

  I have 2 databases:

  -news_posts
     -id
     -title
     -body

  -comments
     -id
     -body
     -newspost_id

  Here are the AppModel classes associated with them:

  // app/models/newspost.php
  class NewsPost extends AppModel {
     var $name = 'NewsPost';
     var $hasMany = 'Comment';
  }

  // app/models/comment.php
  class Comment extends AppModel {
     var $name = 'Comment';
  }

  The problem is when i call $this-NewsPost-find('all'); from a
  controller that var $uses = 'NewsPost';, I get this array:

  Array
  (
     [0] = Array
         (
             [NewsPost] = Array
                 (
                     [id] = 10
                     [Title] = Cool, This works! LOL
                     [Body] = Wow, this really works! OMG LOL OMG
  EDITING WORKS FINE
                     [Time] = 1254685359
                 )

         )

  )

  As you can see, there is no [Comment] array in the sub-array [0].

  Here is the data for my tables:

  news_posts:

    id   |         title       |        body       |
    10  |   News Title   |   News Body   |

  comments:

    id   |            body          |       newspost_id       |
    1    |   Comment Body   |             10                |

  Any help would be greatly appreciated.

  Thanks.
 


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



Model association validation

2009-09-30 Thread Daniel

Hi, I'm sorry if this is a silly question, but I just wanted to check
this to make sure I get it right from the start.

I've just finished building the tables that I'm going to use for my
project and am about to use Bake to build the models. Some of the
Models have BelongTo associations, i.e. I've got a User model and a
Chapter model, with the Chapter model featuring a user_id property
used to associate it with the User model.

When baking that model, before I can set-up the associations it's
asking me to provide the validation criteria. The default for the
Chapter-id is 29 (no validation), but when it gets to Chapter-
user_id, the default becomes 21 (numeric).

What I wanted to check to see is if these should be set to numeric, no
validation, something else, or maybe if it's not even important?

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



Auto-model association doesn't work

2009-08-20 Thread buzachis.a...@gmail.com

Hey everyone.

I have 2 models: User (hasOne) Character (belongsTo) User.

Everything works great on my laptop. When I move it to a server,
somehow, it can't find associations in models. If I do a find('first',
condition id) i get only the User (not the Character too, and YES it
exists in DB), even if I do $this-User-recursive = 1,2... or add
'recursiove' in find options.

If before the find I manualy bindModel them it works (but I don't want
to do this stuff for all my associations). Somehow cake is ignoring my
associations in model files on the other machine and I don't
understand why.

Database exactly the same on both servers, php 5+ on both.

Maybe there is something simple that I'm missing.

Thank you,
Buzachis Aris

--~--~-~--~~~---~--~~
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: Auto-model association doesn't work

2009-08-20 Thread Brendon Kozlowski (Realm)

Have you tried clearing your app/tmp/cache folders to remove that as
being the cause of the issue?

On Aug 20, 4:19 am, buzachis.a...@gmail.com
buzachis.a...@gmail.com wrote:
 Hey everyone.

 I have 2 models: User (hasOne) Character (belongsTo) User.

 Everything works great on my laptop. When I move it to a server,
 somehow, it can't find associations in models. If I do a find('first',
 condition id) i get only the User (not the Character too, and YES it
 exists in DB), even if I do $this-User-recursive = 1,2... or add
 'recursiove' in find options.

 If before the find I manualy bindModel them it works (but I don't want
 to do this stuff for all my associations). Somehow cake is ignoring my
 associations in model files on the other machine and I don't
 understand why.

 Database exactly the same on both servers, php 5+ on both.

 Maybe there is something simple that I'm missing.

 Thank you,
 Buzachis Aris
--~--~-~--~~~---~--~~
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: Auto-model association doesn't work

2009-08-20 Thread Dr. Loboto

Clear caches and check filenames. All files must be strictly
lowercase. Cake just do not load your models as cannot find files.

On Aug 20, 3:19 pm, buzachis.a...@gmail.com
buzachis.a...@gmail.com wrote:
 Hey everyone.

 I have 2 models: User (hasOne) Character (belongsTo) User.

 Everything works great on my laptop. When I move it to a server,
 somehow, it can't find associations in models. If I do a find('first',
 condition id) i get only the User (not the Character too, and YES it
 exists in DB), even if I do $this-User-recursive = 1,2... or add
 'recursiove' in find options.

 If before the find I manualy bindModel them it works (but I don't want
 to do this stuff for all my associations). Somehow cake is ignoring my
 associations in model files on the other machine and I don't
 understand why.

 Database exactly the same on both servers, php 5+ on both.

 Maybe there is something simple that I'm missing.

 Thank you,
 Buzachis Aris
--~--~-~--~~~---~--~~
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: Model Association via conditions fails!

2009-07-23 Thread lapinski




http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/

Lapinski


ohneworte-2 wrote:
 
 
 Hello Together,
 I want to link two Models without using a Foreign Key, but using some
 Conditions instead. Here is my example:
 
 Model:
 -
 class Category extends AppModel {
   var $name = Category;
   var $actsAs = array(Containable);
 
   var $hasMany = array(
   Zone = array(
   foreignKey = false,
   conditions = array(
   AND = array(Category.width = Zone.width, 
 Category.height =
 Zone.height)
   )
   )
   );
 }
 
 Controller:
 --
 $category = $this-Category-find(first, array(
   conditions = array(Category.id = 1),
   contain = array(
   Zone
   )
 ));
 
 Result:
 --
SQL Error: 1054: Unknown column 'Category.width' in 'where clause'
 
 That seems clear if you make a look on the generated Query:
SELECT ... FROM 'zones' AS 'Zone' WHERE (('Category'.'width' =
'Zone'.'width') AND ('Category'.'height' = 'Zone'.'height')) 
 
 No Join occurs - but why? Can anybody help me out?
 I appreciate any help on this issue.
 
 Regards.
  
 
 

-- 
View this message in context: 
http://www.nabble.com/Model-Association-via-%22conditions%22-fails%21-tp23213390p24621578.html
Sent from the CakePHP mailing list archive at Nabble.com.


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



Re: Model association problem

2009-07-17 Thread Zoran Kovac
Here are some of the table fields. it's the table USER, GROUPS and MEDICIANL
DEVICE.
In short relatons are: ser should be in one group and have many MedDevice,
group should have one user, medicinal
device should have only one user.


CREATE  TABLE IF NOT EXISTS `baza2`.`USER` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `UserName` VARCHAR(45) NULL ,
  `Password` VARCHAR(45) NULL COMMENT '
' ,
  `Surname` VARCHAR(45) NULL ,
  `Name` VARCHAR(45) NULL ,
  `groups_id` INT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_USER_GROUPS` (`groups_id` ASC) ,
  CONSTRAINT `fk_USER_GROUPS`
FOREIGN KEY (`groups_id` )
REFERENCES `baza2`.`GROUPS` (`id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -
-- Table `baza2`.`MANUFACTURER`
-- -
CREATE  TABLE IF NOT EXISTS `baza2`.`MANUFACTURER` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `Name` VARCHAR(45) NULL ,
  `Address` VARCHAR(45) NULL ,
  `Phone` VARCHAR(45) NULL ,
  `Contact` VARCHAR(45) NULL ,
  `Mail` VARCHAR(45) NULL ,
  `user_id` INT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_MANUFACTURER_USER` (`user_id` ASC) ,
  CONSTRAINT `fk_MANUFACTURER_USER`
FOREIGN KEY (`user_id` )
REFERENCES `baza2`.`USER` (`id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -
-- Table `baza2`.`MEDICINAL_DEVICE`
-- -
CREATE  TABLE IF NOT EXISTS `baza2`.`MEDICINAL_DEVICE` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `Name` VARCHAR(45) CHARACTER SET 'big5' COLLATE 'big5_chinese_ci' NULL
COMMENT '' ,
  `ActiveIng` VARCHAR(45) NULL ,
  `PharmaForm` VARCHAR(45) NULL ,
  `RouteAdministration` VARCHAR(45) NULL ,
  `DailyDose` VARCHAR(45) NULL ,
  `user_id` INT NULL ,
  `manufacturer_id` INT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_MEDICINAL_DEVICE_USER` (`user_id` ASC) ,
  INDEX `fk_MEDICINAL_DEVICE_MANUFACTURER` (`manufacturer_id` ASC) ,
  CONSTRAINT `fk_MEDICINAL_DEVICE_USER`
FOREIGN KEY (`user_id` )
REFERENCES `baza2`.`USER` (`id` )
ON DELETE CASCADE
ON UPDATE CASCADE,
  CONSTRAINT `fk_MEDICINAL_DEVICE_MANUFACTURER`
FOREIGN KEY (`manufacturer_id` )
REFERENCES `baza2`.`MANUFACTURER` (`id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;


On Thu, Jul 16, 2009 at 4:02 PM, Carlos Gonzalez Lavin 
carloslavi...@gmail.com wrote:

 Maybe if you described the tables' fields.. theres gotta be some convention
 breaking there

 2009/7/16 Zoran Kovac zoko2...@gmail.com


 Hi!

 I'm having a dilema, maybe the better word is that I'm puzzled.

 The problem is when I'm baking models. The console doesn't detect
 relations between tables automatically. For instance, the console does
 recognize all the tables from the database, but when it's triying to
 detect associations it comes up with the result like on the end of
 this post or just skips to 'Look okay?'. It the noted example on end
 of the post, I manage to create a complete model (with association to
 user), but association among other models fails.

 So my question's are:

 1. Am I breaking some convetions and it's not working?
 2. Could it be that I'm using InnoDB type?
 3. Anything else?

 Any kind of sugestions is appreciated. Thnx.


 Possible Models based on your current database:
 1. DocumentsDevice
 2. Group
 3. InvestigationalSite
 4. Investigator
 5. Manufacturer
 6. MedicinalDevice
 7. MedicinalProduct
 8. ReportDevice
 9. ReportProduct
 10. SoaDevice
 11. SoaProduct
 12. User
 Enter a number from the list above, type in the name of another model,
 or 'q' to
  exit
 [q]  2
 Would you like to supply validation criteria for the fields in your
 model? (y/n)

 [y]  n
 Would you like to define model associations (hasMany, hasOne,
 belongsTo, etc.)?
 (y/n)
 [y]  y
 One moment while the associations are detected.
 ---
 Please confirm the following associations:
 ---
 Would you like to define some additional model associations? (y/n)
 [n] 

 





 



-- 
Zoran Kovac
091/ 588 6175
V.Gorica

--~--~-~--~~~---~--~~
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: Model association problem

2009-07-17 Thread leop

The database table names ought to be plural, viz: MEDICINAL_DEVICES,
USERS etc. Cake is intelligent enough to handle plurals such as
COMPANIES (COMPANY).

In the model definitions, the model will be the capitalised singular
version of the tablename, e.g. User

Foreign keys are singular, e.g. user_id

All these things can be changed where required, but will generally
break the bake if they don't follow the convention.

see: http://book.cakephp.org/view/24/Model-and-Database-Conventions

--~--~-~--~~~---~--~~
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: Model association problem

2009-07-17 Thread Carlos Lavin
Tables are supposed to be plural (users,groups,medicinal_devices) and the
foreign keys singular(user_id,group_id...)
Change it and give it another shot =)

2009/7/17 Zoran Kovac zoko2...@gmail.com

 Here are some of the table fields. it's the table USER, GROUPS and
 MEDICIANL DEVICE.
 In short relatons are: ser should be in one group and have many MedDevice,
 group should have one user, medicinal
 device should have only one user.


 CREATE  TABLE IF NOT EXISTS `baza2`.`USER` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `UserName` VARCHAR(45) NULL ,
   `Password` VARCHAR(45) NULL COMMENT '
 ' ,
   `Surname` VARCHAR(45) NULL ,
   `Name` VARCHAR(45) NULL ,
   `groups_id` INT NULL ,
   PRIMARY KEY (`id`) ,
   INDEX `fk_USER_GROUPS` (`groups_id` ASC) ,
   CONSTRAINT `fk_USER_GROUPS`
 FOREIGN KEY (`groups_id` )
 REFERENCES `baza2`.`GROUPS` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE)
 ENGINE = InnoDB;


 -- -
 -- Table `baza2`.`MANUFACTURER`
 -- -
 CREATE  TABLE IF NOT EXISTS `baza2`.`MANUFACTURER` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `Name` VARCHAR(45) NULL ,
   `Address` VARCHAR(45) NULL ,
   `Phone` VARCHAR(45) NULL ,
   `Contact` VARCHAR(45) NULL ,
   `Mail` VARCHAR(45) NULL ,
   `user_id` INT NULL ,
   PRIMARY KEY (`id`) ,
   INDEX `fk_MANUFACTURER_USER` (`user_id` ASC) ,
   CONSTRAINT `fk_MANUFACTURER_USER`
 FOREIGN KEY (`user_id` )
 REFERENCES `baza2`.`USER` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE)
 ENGINE = InnoDB;


 -- -
 -- Table `baza2`.`MEDICINAL_DEVICE`
 -- -
 CREATE  TABLE IF NOT EXISTS `baza2`.`MEDICINAL_DEVICE` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `Name` VARCHAR(45) CHARACTER SET 'big5' COLLATE 'big5_chinese_ci' NULL
 COMMENT '' ,
   `ActiveIng` VARCHAR(45) NULL ,
   `PharmaForm` VARCHAR(45) NULL ,
   `RouteAdministration` VARCHAR(45) NULL ,
   `DailyDose` VARCHAR(45) NULL ,
   `user_id` INT NULL ,
   `manufacturer_id` INT NULL ,
   PRIMARY KEY (`id`) ,
   INDEX `fk_MEDICINAL_DEVICE_USER` (`user_id` ASC) ,
   INDEX `fk_MEDICINAL_DEVICE_MANUFACTURER` (`manufacturer_id` ASC) ,
   CONSTRAINT `fk_MEDICINAL_DEVICE_USER`
 FOREIGN KEY (`user_id` )
 REFERENCES `baza2`.`USER` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE,
   CONSTRAINT `fk_MEDICINAL_DEVICE_MANUFACTURER`
 FOREIGN KEY (`manufacturer_id` )
 REFERENCES `baza2`.`MANUFACTURER` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE)
 ENGINE = InnoDB;



 On Thu, Jul 16, 2009 at 4:02 PM, Carlos Gonzalez Lavin 
 carloslavi...@gmail.com wrote:

 Maybe if you described the tables' fields.. theres gotta be some
 convention breaking there

 2009/7/16 Zoran Kovac zoko2...@gmail.com


 Hi!

 I'm having a dilema, maybe the better word is that I'm puzzled.

 The problem is when I'm baking models. The console doesn't detect
 relations between tables automatically. For instance, the console does
 recognize all the tables from the database, but when it's triying to
 detect associations it comes up with the result like on the end of
 this post or just skips to 'Look okay?'. It the noted example on end
 of the post, I manage to create a complete model (with association to
 user), but association among other models fails.

 So my question's are:

 1. Am I breaking some convetions and it's not working?
 2. Could it be that I'm using InnoDB type?
 3. Anything else?

 Any kind of sugestions is appreciated. Thnx.


 Possible Models based on your current database:
 1. DocumentsDevice
 2. Group
 3. InvestigationalSite
 4. Investigator
 5. Manufacturer
 6. MedicinalDevice
 7. MedicinalProduct
 8. ReportDevice
 9. ReportProduct
 10. SoaDevice
 11. SoaProduct
 12. User
 Enter a number from the list above, type in the name of another model,
 or 'q' to
  exit
 [q]  2
 Would you like to supply validation criteria for the fields in your
 model? (y/n)

 [y]  n
 Would you like to define model associations (hasMany, hasOne,
 belongsTo, etc.)?
 (y/n)
 [y]  y
 One moment while the associations are detected.
 ---
 Please confirm the following associations:
 ---
 Would you like to define some additional model associations? (y/n)
 [n] 

 









 --
 Zoran Kovac
 091/ 588 6175
 V.Gorica


 


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

Re: Model association problem

2009-07-17 Thread Zoran Kovac
Aargh...name conventions, still not used to it. Thanks for the heads up,
knew it had to be something obvoius. It always is ;))
Now it works like a charm.

-- 
Zoran Kovac
091/ 588 6175
V.Gorica



On Fri, Jul 17, 2009 at 9:53 AM, Carlos Lavin carloslavi...@gmail.comwrote:

 Tables are supposed to be plural (users,groups,medicinal_devices) and the
 foreign keys singular(user_id,group_id...)
 Change it and give it another shot =)

 2009/7/17 Zoran Kovac zoko2...@gmail.com

 Here are some of the table fields. it's the table USER, GROUPS and
 MEDICIANL DEVICE.
 In short relatons are: ser should be in one group and have many MedDevice,
 group should have one user, medicinal
 device should have only one user.


 CREATE  TABLE IF NOT EXISTS `baza2`.`USER` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `UserName` VARCHAR(45) NULL ,
   `Password` VARCHAR(45) NULL COMMENT '
 ' ,
   `Surname` VARCHAR(45) NULL ,
   `Name` VARCHAR(45) NULL ,
   `groups_id` INT NULL ,
   PRIMARY KEY (`id`) ,
   INDEX `fk_USER_GROUPS` (`groups_id` ASC) ,
   CONSTRAINT `fk_USER_GROUPS`
 FOREIGN KEY (`groups_id` )
 REFERENCES `baza2`.`GROUPS` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE)
 ENGINE = InnoDB;


 -- -
 -- Table `baza2`.`MANUFACTURER`
 -- -
 CREATE  TABLE IF NOT EXISTS `baza2`.`MANUFACTURER` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `Name` VARCHAR(45) NULL ,
   `Address` VARCHAR(45) NULL ,
   `Phone` VARCHAR(45) NULL ,
   `Contact` VARCHAR(45) NULL ,
   `Mail` VARCHAR(45) NULL ,
   `user_id` INT NULL ,
   PRIMARY KEY (`id`) ,
   INDEX `fk_MANUFACTURER_USER` (`user_id` ASC) ,
   CONSTRAINT `fk_MANUFACTURER_USER`
 FOREIGN KEY (`user_id` )
 REFERENCES `baza2`.`USER` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE)
 ENGINE = InnoDB;


 -- -
 -- Table `baza2`.`MEDICINAL_DEVICE`
 -- -
 CREATE  TABLE IF NOT EXISTS `baza2`.`MEDICINAL_DEVICE` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `Name` VARCHAR(45) CHARACTER SET 'big5' COLLATE 'big5_chinese_ci' NULL
 COMMENT '' ,
   `ActiveIng` VARCHAR(45) NULL ,
   `PharmaForm` VARCHAR(45) NULL ,
   `RouteAdministration` VARCHAR(45) NULL ,
   `DailyDose` VARCHAR(45) NULL ,
   `user_id` INT NULL ,
   `manufacturer_id` INT NULL ,
   PRIMARY KEY (`id`) ,
   INDEX `fk_MEDICINAL_DEVICE_USER` (`user_id` ASC) ,
   INDEX `fk_MEDICINAL_DEVICE_MANUFACTURER` (`manufacturer_id` ASC) ,
   CONSTRAINT `fk_MEDICINAL_DEVICE_USER`
 FOREIGN KEY (`user_id` )
 REFERENCES `baza2`.`USER` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE,
   CONSTRAINT `fk_MEDICINAL_DEVICE_MANUFACTURER`
 FOREIGN KEY (`manufacturer_id` )
 REFERENCES `baza2`.`MANUFACTURER` (`id` )
 ON DELETE CASCADE
 ON UPDATE CASCADE)
 ENGINE = InnoDB;



 On Thu, Jul 16, 2009 at 4:02 PM, Carlos Gonzalez Lavin 
 carloslavi...@gmail.com wrote:

 Maybe if you described the tables' fields.. theres gotta be some
 convention breaking there

 2009/7/16 Zoran Kovac zoko2...@gmail.com


 Hi!

 I'm having a dilema, maybe the better word is that I'm puzzled.

 The problem is when I'm baking models. The console doesn't detect
 relations between tables automatically. For instance, the console does
 recognize all the tables from the database, but when it's triying to
 detect associations it comes up with the result like on the end of
 this post or just skips to 'Look okay?'. It the noted example on end
 of the post, I manage to create a complete model (with association to
 user), but association among other models fails.

 So my question's are:

 1. Am I breaking some convetions and it's not working?
 2. Could it be that I'm using InnoDB type?
 3. Anything else?

 Any kind of sugestions is appreciated. Thnx.


 Possible Models based on your current database:
 1. DocumentsDevice
 2. Group
 3. InvestigationalSite
 4. Investigator
 5. Manufacturer
 6. MedicinalDevice
 7. MedicinalProduct
 8. ReportDevice
 9. ReportProduct
 10. SoaDevice
 11. SoaProduct
 12. User
 Enter a number from the list above, type in the name of another model,
 or 'q' to
  exit
 [q]  2
 Would you like to supply validation criteria for the fields in your
 model? (y/n)

 [y]  n
 Would you like to define model associations (hasMany, hasOne,
 belongsTo, etc.)?
 (y/n)
 [y]  y
 One moment while the associations are detected.
 ---
 Please confirm the following associations:
 ---
 Would you like to define some additional model associations? (y/n)
 [n] 

 









 --
 Zoran Kovac
 091/ 588 6175
 V.Gorica





 



Model association problem

2009-07-16 Thread Zoran Kovac

Hi!

I'm having a dilema, maybe the better word is that I'm puzzled.

The problem is when I'm baking models. The console doesn't detect
relations between tables automatically. For instance, the console does
recognize all the tables from the database, but when it's triying to
detect associations it comes up with the result like on the end of
this post or just skips to 'Look okay?'. It the noted example on end
of the post, I manage to create a complete model (with association to
user), but association among other models fails.

So my question's are:

1. Am I breaking some convetions and it's not working?
2. Could it be that I'm using InnoDB type?
3. Anything else?

Any kind of sugestions is appreciated. Thnx.


Possible Models based on your current database:
1. DocumentsDevice
2. Group
3. InvestigationalSite
4. Investigator
5. Manufacturer
6. MedicinalDevice
7. MedicinalProduct
8. ReportDevice
9. ReportProduct
10. SoaDevice
11. SoaProduct
12. User
Enter a number from the list above, type in the name of another model,
or 'q' to
 exit
[q]  2
Would you like to supply validation criteria for the fields in your
model? (y/n)

[y]  n
Would you like to define model associations (hasMany, hasOne,
belongsTo, etc.)?
(y/n)
[y]  y
One moment while the associations are detected.
---
Please confirm the following associations:
---
Would you like to define some additional model associations? (y/n)
[n] 



--~--~-~--~~~---~--~~
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: Model association problem

2009-07-16 Thread Carlos Gonzalez Lavin
Maybe if you described the tables' fields.. theres gotta be some convention
breaking there

2009/7/16 Zoran Kovac zoko2...@gmail.com


 Hi!

 I'm having a dilema, maybe the better word is that I'm puzzled.

 The problem is when I'm baking models. The console doesn't detect
 relations between tables automatically. For instance, the console does
 recognize all the tables from the database, but when it's triying to
 detect associations it comes up with the result like on the end of
 this post or just skips to 'Look okay?'. It the noted example on end
 of the post, I manage to create a complete model (with association to
 user), but association among other models fails.

 So my question's are:

 1. Am I breaking some convetions and it's not working?
 2. Could it be that I'm using InnoDB type?
 3. Anything else?

 Any kind of sugestions is appreciated. Thnx.


 Possible Models based on your current database:
 1. DocumentsDevice
 2. Group
 3. InvestigationalSite
 4. Investigator
 5. Manufacturer
 6. MedicinalDevice
 7. MedicinalProduct
 8. ReportDevice
 9. ReportProduct
 10. SoaDevice
 11. SoaProduct
 12. User
 Enter a number from the list above, type in the name of another model,
 or 'q' to
  exit
 [q]  2
 Would you like to supply validation criteria for the fields in your
 model? (y/n)

 [y]  n
 Would you like to define model associations (hasMany, hasOne,
 belongsTo, etc.)?
 (y/n)
 [y]  y
 One moment while the associations are detected.
 ---
 Please confirm the following associations:
 ---
 Would you like to define some additional model associations? (y/n)
 [n] 

 


 


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



model association question

2009-06-18 Thread Jacob Everist
I have a project and I am trying to figure out the best way to associate my
models and how to structure them.   In particular, I have something like a
polymorphic association situation.

I want to have a table of transactions, that list the transfers of money
from one user to another.  The transactions refer to either an auction or a
fixed-price sale.

So I have a Sale model, an Auction model, and a Transaction model.  But the
transaction should associate to either an auction or a sale, but not both.
How can I do this?   How can avoid making two transaction models, one for
SaleTransactions, and one for AuctionTransactions?  Instead, just a
Transaction model that can refer to any other type of model that involves an
exchange of money.


-- 

Jacob Everist

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



Model association w/ multipart key

2009-05-21 Thread michaelc

Hi all. Just asking to rely on the wisdom of those with greater
experience than me. My Settings model has fields id, group, key, and
value, while my SettingOptions model has fields id, group, key, type,
and default. My intent is to use the data available in the
setting_options table to validate correct value types being saved to
the settings table on the fly - these then will be read elsewhere.  My
problem is - I don't know how to bind the two tables. I could implode
('.', array($group, $key)) before storing in the table, but I fear
maintenance issues later. Any advice or suggestions from the great old
ones? (Obviously I'd like to keep clear of a static class variable
with ClassRegistry::init.)

--
Thanks in advance,

Michaelc

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



Model Association based on user_id

2009-05-14 Thread Dan

I have two models, Content and Score. The Score model has a reference
to a User (user_id) the Content model (content_id). Therefore, there
can be many Scores associated with Content. So far, this is sounding
like a cut-and-dry Content - hasMany - Score association, right?

Now, when I retrieve Contents, I only want the Score associated with a
particular user; namely, the currently logged-in user. Ideally, I
would want a hasOne relationship based on the user_id of the user that
is logged in. However, the only way to find out that user_id is from
one of my controllers, and you can't use controller logic in a Model.

These are the following solutions I have come up with:

1) Create a hasMany association in Content and pass user_id in the
parameters of all of my find(...) function calls
2) Create a hasMany association in Content, make the Content use the
Containable behavior, and call Content-Contain('Score.user_id =
$user_id')
3) Use bindModel(...) to add the association to the Content model in
the controllers that use it

Is there a better way I should be going about this?

Thanks,
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model Association Not Creating Query Joins

2009-04-25 Thread James K

Start from the AccountAlert model rather than the Alert model. Use
contain as well.

$alert_ids = $this-AccountAlert-find (
'all',
array (
'contain' = array(),
'conditions'=   array (
'AccountAlert.account_id'  = $account_id
),
'fields'=   array('alert_id'),
)
);

You should also use contain to restrict the number of models involved
in each query. Containing an empty array (or an empty string, I can't
remember) will tell your query to not join any other models.

- James

On Apr 23, 8:45 pm, Rob Wilkerson r...@robwilkerson.org wrote:
 I have an Alert model, an Account model and an AccountAlert model:

 Alert hasMany AccountAlert
 Account hasMany AccountAlert
 AccountAlert belongsTo ( Alert, Account )

 AccountAlert has several other defining fields, so it has its own
 primary key in the database as well as being its own model. IOW, it's
 more than a simple linking table. It has foreign keys to the alerts
 and accounts tables (alert_id and account_id, respectively).

 From AccountModel, I'm trying to retrieve all of the Alerts for a
 given Account.  If I try a simple find:

 $this-Alert-find ( 'all' )

 I get each Alert and each AccountAlert that has that alert. If,
 however, I try to restrict by the account_id then I get an unknown
 column error:

 $alert_ids = $this-Alert-find (
         'all',
         array (
                 'conditions'    =   array (
                         'AccountAlert.account_id'  = $account_id
                 ),
                 'fields'                =   array('id'),
         )
 );

 Looking at the debug SQL, no join is being created. Since the model
 associations are intact (I assume this is the case since the simple
 find() returns data for both models), should CakePHP be building the
 join automagically and, therefore, understanding the
 AccountAlert.account_id syntax in my condition?

 Even being relatively new to CakePHP, it still seems like I should
 have run into this before, but I can't remember having seen this. Any
 push in the right direction would be much 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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model Association Not Creating Query Joins

2009-04-25 Thread Rob Wilkerson


On Apr 25, 9:55 am, James K james.m.k...@gmail.com wrote:
 Start from the AccountAlert model rather than the Alert model. Use
 contain as well.

 $alert_ids = $this-AccountAlert-find (
         'all',
         array (
                 'contain' = array(),
                 'conditions'    =   array (
                         'AccountAlert.account_id'  = $account_id
                 ),
                 'fields'                =   array('alert_id'),
         )
 );

 You should also use contain to restrict the number of models involved
 in each query. Containing an empty array (or an empty string, I can't
 remember) will tell your query to not join any other models.

Thanks, everyone. Has it always been like this? For some reason, I
would have sworn that in the past I've done something like this:

$this-AccountAlert-find (
   'all',
   array (
  'conditions' = array (
 'AccountAlert.active' = 1
  ),
  'order' = 'Alert.priority'
   )
);

Note the different models being used in the conditions and order
parameters. Has that never been possible?

Thanks again for the help. I'll definitely be digging into the
containable behavior.
--~--~-~--~~~---~--~~
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: Model Association Not Creating Query Joins

2009-04-24 Thread Walther

In cases like what you are looking at it tends to work a bit better if
you rather do the find on the model you want to filter.

Something like:

$alert_ids = $this-Alert-AccountAlert-find (
'all',
array (
'conditions'=   array (
'AccountAlert.account_id'  = $account_id
),
'fields'=   array('Alert.id'),
)
);

That might work (Sorry, sitting at university, can't test).
Otherwise you can try the containable behaviour, that should be able
to do what you wish.

On Apr 24, 2:45 am, Rob Wilkerson r...@robwilkerson.org wrote:
 I have an Alert model, an Account model and an AccountAlert model:

 Alert hasMany AccountAlert
 Account hasMany AccountAlert
 AccountAlert belongsTo ( Alert, Account )

 AccountAlert has several other defining fields, so it has its own
 primary key in the database as well as being its own model. IOW, it's
 more than a simple linking table. It has foreign keys to the alerts
 and accounts tables (alert_id and account_id, respectively).

 From AccountModel, I'm trying to retrieve all of the Alerts for a
 given Account.  If I try a simple find:

 $this-Alert-find ( 'all' )

 I get each Alert and each AccountAlert that has that alert. If,
 however, I try to restrict by the account_id then I get an unknown
 column error:

 $alert_ids = $this-Alert-find (
 'all',
 array (
 'conditions'=   array (
 'AccountAlert.account_id'  = $account_id
 ),
 'fields'=   array('id'),
 )
 );

 Looking at the debug SQL, no join is being created. Since the model
 associations are intact (I assume this is the case since the simple
 find() returns data for both models), should CakePHP be building the
 join automagically and, therefore, understanding the
 AccountAlert.account_id syntax in my condition?

 Even being relatively new to CakePHP, it still seems like I should
 have run into this before, but I can't remember having seen this. Any
 push in the right direction would be much 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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Model Association via conditions fails!

2009-04-24 Thread ohneworte

Hello Together,
I want to link two Models without using a Foreign Key, but using some
Conditions instead. Here is my example:

Model:
-
class Category extends AppModel {
var $name = Category;
var $actsAs = array(Containable);

var $hasMany = array(
Zone = array(
foreignKey = false,
conditions = array(
AND = array(Category.width = Zone.width, 
Category.height =
Zone.height)
)
)
);
}

Controller:
--
$category = $this-Category-find(first, array(
conditions = array(Category.id = 1),
contain = array(
Zone
)
));

Result:
--
SQL Error: 1054: Unknown column 'Category.width' in 'where clause'

That seems clear if you make a look on the generated Query:
SELECT ... FROM 'zones' AS 'Zone' WHERE (('Category'.'width' = 
'Zone'.'width') AND ('Category'.'height' = 'Zone'.'height')) 

No Join occurs - but why? Can anybody help me out?
I appreciate any help on this issue.

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



Model Association Not Creating Query Joins

2009-04-23 Thread Rob Wilkerson

I have an Alert model, an Account model and an AccountAlert model:

Alert hasMany AccountAlert
Account hasMany AccountAlert
AccountAlert belongsTo ( Alert, Account )

AccountAlert has several other defining fields, so it has its own
primary key in the database as well as being its own model. IOW, it's
more than a simple linking table. It has foreign keys to the alerts
and accounts tables (alert_id and account_id, respectively).

From AccountModel, I'm trying to retrieve all of the Alerts for a
given Account.  If I try a simple find:

$this-Alert-find ( 'all' )

I get each Alert and each AccountAlert that has that alert. If,
however, I try to restrict by the account_id then I get an unknown
column error:

$alert_ids = $this-Alert-find (
'all',
array (
'conditions'=  array (
'AccountAlert.account_id'  = $account_id
),
'fields'=  array('id'),
)
);

Looking at the debug SQL, no join is being created. Since the model
associations are intact (I assume this is the case since the simple
find() returns data for both models), should CakePHP be building the
join automagically and, therefore, understanding the
AccountAlert.account_id syntax in my condition?

Even being relatively new to CakePHP, it still seems like I should
have run into this before, but I can't remember having seen this. Any
push in the right direction would be much 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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Model association

2008-12-26 Thread mona

How to make association between three of four tables because i m
fetching data on my table from three different tables
--~--~-~--~~~---~--~~
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: Model association

2008-12-26 Thread MikeB

var $hasmany = array('People', 'Post', 'Tag);

On Dec 26, 11:51 am, mona poojapinj...@gmail.com wrote:
 How to make association between three of four tables because i m
 fetching data on my table from three different tables
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



What's the Model Association for a Lookup Table

2008-12-13 Thread Rob Wilkerson

I have a vendors table that contains a field named address_id that
is a foreign key to addresses.id. If I define the models as shown
below then I'm unable to request a scaffolded version of /vendors/
without getting an error: Unknown column 'Address.vendor_id' in 'on
clause'.  I don't want a vendor_id in the addresses table because I
need to share that data with other tables later in the dev cycle (e.g.
the volunteers table).

class Vendor extends AppModel {

public $name   = 'Vendor';
public $hasOne = array ( 'CommercialVendor', 'Address' );

}

class Address extends AppModel {

public $name  = 'Address';
public $belongsTo = array ( 'Vendor' );

}

If I remove 'Address' from the hasOne array on the Vendor model,
everything renders, but there's no association between the two. I'm
new to Cake and I think I'm thinking about this incorrectly, but I
don't know what I'm missing.

Any insight would be appreciated.

Rob
--~--~-~--~~~---~--~~
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: What's the Model Association for a Lookup Table

2008-12-13 Thread Rob Wilkerson


Rob Wilkerson wrote:
 I have a vendors table that contains a field named address_id that
 is a foreign key to addresses.id. If I define the models as shown
 below then I'm unable to request a scaffolded version of /vendors/
 without getting an error: Unknown column 'Address.vendor_id' in 'on
 clause'.  I don't want a vendor_id in the addresses table because I
 need to share that data with other tables later in the dev cycle (e.g.
 the volunteers table).

 class Vendor extends AppModel {

   public $name   = 'Vendor';
   public $hasOne = array ( 'CommercialVendor', 'Address' );

 }

 class Address extends AppModel {

   public $name  = 'Address';
   public $belongsTo = array ( 'Vendor' );

 }

 If I remove 'Address' from the hasOne array on the Vendor model,
 everything renders, but there's no association between the two. I'm
 new to Cake and I think I'm thinking about this incorrectly, but I
 don't know what I'm missing.

A little time away from it and a re-read of TFM pointed out the error
of my ways. I was defining the relationship intuitively rather than
logically. Intuitively, each vendor has an address, but logically each
address has a vendor:

class Vendor extends AppModel {

public $name   = 'Vendor';
public $hasOne = array ( 'CommercialVendor' );

}

class Address extends AppModel {

public $name  = 'Address';
public $hasOne = array ( 'Vendor' );

}

This seems to work more like what I'd expect.
--~--~-~--~~~---~--~~
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 Model association trouble.

2008-12-10 Thread Genu

Hello, I'm using the HABTM model association, with my database
structure as follows:

table: contractors
fields:
Id
name
address
state
zip
fax

table: projects
fields:
id
title
address
state
zip
type
value
size
..etc.

a join table:
contractors_projects
fields:
id
contractor_id
project_id


My question is, how can I insert data in to both contractors table
and projects table while maintaining the association?

My data is generated automatically, it looks something like this:

array(1) {
  [Project]=
  array(11) {
[id]=
NULL
[title]=
string(24) Title of project goes here
[address]=
string(43)  123 Address here 
[state]=
string(2) NC
[zip]=
12345
[type]=
string(16) New
[value]=
string(0) 
[size]=
string(17) 1000
  }
}

I then have an array of all the contractors that are associated with
this project:

array(4) {
  [0]=
  array(8) {
[id]=
NULL
[name]=
string(36) Contractor 1
[address]=
string(34)  Address of Contractor 1, 
[state]=
string(2) NC
[zip]=
string(5) 12345
[fax]=
string(10) 1231231234
  }
  [1]=
  array(8) {
[id]=
NULL
[name]=
string(28) Contractor 2
[address]=
string(34) Address of Contractor 2 
[state]=
string(2) NC
[zip]=
string(5) 12345
[fax]=
NULL
  }
  [2]=
  array(8) {
[id]=
NULL
[name]=
string(32) Contractor 3
[address]=
string(43) Address of Contractor 3 
[state]=
string(2) NC
[zip]=
string(5) 12345
[fax]=
string(10) 1231231234
  }
}


How can I store (and in which order) the data in order to insert a new
project, AND a new contractor, but maintaining the association (that
the contractor belongs to that particular project)?


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



Auth - User model association problem

2008-10-09 Thread Duncan

Hi,

I have a User model, which belongsTo a Group model. When using the
user model itself, I get the correct association data for the Group
model, but when using the Auth component, then I only get the User
model itself in the auth session array, e.g.:

[Auth] = Array
(
[User] = Array
(
[id] = 2
[username] = admin
[group_id] = 1
)

)

whereas I would expect something like:

[Auth] = Array
(
[User] = Array
(
[id] = 2
[username] = admin
[group_id] = 1
)

[Group] = Array
(
[id] = 1
[name] = Admins
)

)

Is the Auth component ignoring the User model associations?

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



Recursive Model association

2008-09-28 Thread [EMAIL PROTECTED]

Hey Bakers,

what is wrong in this association ? I can't get the recursive Relation
running.
I need the location name for routing the image.

It should be stored in. But is doesn'exists.
$data[Picture][Gallery][Location][location_name]

Here is the code:

?php
class Gallery extends AppModel {
var $name = 'Gallery';
var $belongsTo = array('Location' = array('className' =
'Location','foreignKey' = 'location_id'));
var $hasMany = array('Pictures' = array('className' =
'Picture','foreignKey' = 'gallery_id','dependent' = false));
}

class Location extends AppModel {
var $name = 'Location';
var $hasMany = array('Gallery' = array('className' =
'Gallery','foreignKey' = 'location_id','dependent' = false));
}

class Picture extends AppModel {
var $name = 'Picture';
var $belongsTo = array(
'Gallery' = array('className' = 
'Gallery','foreignKey' =
'gallery_id'),
'User' = array('className' = 'User','foreignKey' = 
'user_id')
);
}

#Controller Action:
$this-Picture-findbyid($id);

?

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



Model association

2008-09-17 Thread VitillO

Hi, i have the following structure for a tshirt online store:

Product HABTM Size
Size HABTM Product

Association table:
products_sizes

The problem is, i need a stocks system.

For example, say i have 50 pieces of S (size) for a particular tshirt,
before using cake i had a column 'stock' in the association table, so
i could retrieve the particular stock of that size, for that product,
but now with cake i dont know how i should make the association.

Any help?

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: Model association

2008-09-17 Thread Luiz Poleto
You can create the column stock in the association table.In the form where
you do the association, you can add a new field for the stock.

At least that was what i understood from your question...

Regards,
Luiz Poleto

2008/9/17 VitillO [EMAIL PROTECTED]


 Hi, i have the following structure for a tshirt online store:

 Product HABTM Size
 Size HABTM Product

 Association table:
 products_sizes

 The problem is, i need a stocks system.

 For example, say i have 50 pieces of S (size) for a particular tshirt,
 before using cake i had a column 'stock' in the association table, so
 i could retrieve the particular stock of that size, for that product,
 but now with cake i dont know how i should make the association.

 Any help?

 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: Model association

2008-09-17 Thread Adam Royle

You can create a model for your habtm association so you can add extra
fields, etc, using the with key. Something like this...

class Product extends AppModel {

...

var $hasAndBelongsToMany = array(
'Size' = array('className' = 'Size',
'with' = 'ProductsSize', // -- this here, class name can be
changed
'joinTable' = 'products_sizes',
'foreignKey' = 'product_id',
'associationForeignKey' = 'size_id',
),
);

}


class ProductsSize extends AppModel {
// and here is your joined class!
}


Hope that helps,
Adam

On Sep 18, 7:07 am, Luiz Poleto [EMAIL PROTECTED] wrote:
 You can create the column stock in the association table.In the form where
 you do the association, you can add a new field for the stock.

 At least that was what i understood from your question...

 Regards,
 Luiz Poleto

 2008/9/17 VitillO [EMAIL PROTECTED]



  Hi, i have the following structure for a tshirt online store:

  Product HABTM Size
  Size HABTM Product

  Association table:
  products_sizes

  The problem is, i need a stocks system.

  For example, say i have 50 pieces of S (size) for a particular tshirt,
  before using cake i had a column 'stock' in the association table, so
  i could retrieve the particular stock of that size, for that product,
  but now with cake i dont know how i should make the association.

  Any help?

  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: Model association

2008-09-17 Thread VitillO

Hi guys, thanks for your replies.

Right now, im my 'add' view of products, im getting a multiple select
for the sizes, where i can select which sizes are available for that
particular product, thats fine. The problem is that i need a stock
number for each of this available sizes, so a multiple select wont
work for me.

An example would be:

[ (checkbox) ] Small --- Stock [ input (a number) ]
[ (checkbox) ] Medium --- Stock [ input (a number) ]
[ (checkbox) ] Large --- Stock [ input (a number) ]

So when i hit submit on the form, i can see the selected sizes for
that product along with the stock value for each one. Thats what i
need to achieve, but i dont know how to make the associations, neither
the necessary models for this to work.

@Adam: how does 'with' parameter works? i cant find the documentation
for it

On Sep 17, 11:28 pm, Adam Royle [EMAIL PROTECTED] wrote:
 You can create a model for your habtm association so you can add extra
 fields, etc, using the with key. Something like this...

 class Product extends AppModel {

 ...

 var $hasAndBelongsToMany = array(
     'Size' = array('className' = 'Size',
         'with' = 'ProductsSize', // -- this here, class name can be
 changed
         'joinTable' = 'products_sizes',
         'foreignKey' = 'product_id',
         'associationForeignKey' = 'size_id',
     ),
 );

 }

 class ProductsSize extends AppModel {
     // and here is your joined class!

 }

 Hope that helps,
 Adam

 On Sep 18, 7:07 am, Luiz Poleto [EMAIL PROTECTED] wrote:

  You can create the column stock in the association table.In the form where
  you do the association, you can add a new field for the stock.

  At least that was what i understood from your question...

  Regards,
  Luiz Poleto

  2008/9/17 VitillO [EMAIL PROTECTED]

   Hi, i have the following structure for a tshirt online store:

   Product HABTM Size
   Size HABTM Product

   Association table:
   products_sizes

   The problem is, i need a stocks system.

   For example, say i have 50 pieces of S (size) for a particular tshirt,
   before using cake i had a column 'stock' in the association table, so
   i could retrieve the particular stock of that size, for that product,
   but now with cake i dont know how i should make the association.

   Any help?

   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: Model association

2008-09-17 Thread teknoid

I explain how with work here,  I think this should be good to get
you started:
http://teknoid.wordpress.com/2008/07/03/notes-on-cakephp-habtm-part-1-the-basics/

Also, just a hint... cake can easily create checkboxes for you
(instead of multi-select).
Just tell it to use 'multiple'='checkbox' in your input() tag.

On Sep 17, 6:59 pm, VitillO [EMAIL PROTECTED] wrote:
 Hi guys, thanks for your replies.

 Right now, im my 'add' view of products, im getting a multiple select
 for the sizes, where i can select which sizes are available for that
 particular product, thats fine. The problem is that i need a stock
 number for each of this available sizes, so a multiple select wont
 work for me.

 An example would be:

 [ (checkbox) ] Small --- Stock [ input (a number) ]
 [ (checkbox) ] Medium --- Stock [ input (a number) ]
 [ (checkbox) ] Large --- Stock [ input (a number) ]

 So when i hit submit on the form, i can see the selected sizes for
 that product along with the stock value for each one. Thats what i
 need to achieve, but i dont know how to make the associations, neither
 the necessary models for this to work.

 @Adam: how does 'with' parameter works? i cant find the documentation
 for it

 On Sep 17, 11:28 pm, Adam Royle [EMAIL PROTECTED] wrote:

  You can create a model for your habtm association so you can add extra
  fields, etc, using the with key. Something like this...

  class Product extends AppModel {

  ...

  var $hasAndBelongsToMany = array(
      'Size' = array('className' = 'Size',
          'with' = 'ProductsSize', // -- this here, class name can be
  changed
          'joinTable' = 'products_sizes',
          'foreignKey' = 'product_id',
          'associationForeignKey' = 'size_id',
      ),
  );

  }

  class ProductsSize extends AppModel {
      // and here is your joined class!

  }

  Hope that helps,
  Adam

  On Sep 18, 7:07 am, Luiz Poleto [EMAIL PROTECTED] wrote:

   You can create the column stock in the association table.In the form where
   you do the association, you can add a new field for the stock.

   At least that was what i understood from your question...

   Regards,
   Luiz Poleto

   2008/9/17 VitillO [EMAIL PROTECTED]

Hi, i have the following structure for a tshirt online store:

Product HABTM Size
Size HABTM Product

Association table:
products_sizes

The problem is, i need a stocks system.

For example, say i have 50 pieces of S (size) for a particular tshirt,
before using cake i had a column 'stock' in the association table, so
i could retrieve the particular stock of that size, for that product,
but now with cake i dont know how i should make the association.

Any help?

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: Model association

2008-09-17 Thread VitillO

Ok guys, it seems i have the data (extra field 'stock' in the
association table) in $this-data when i edit a Product, something
like this, so the association table is auto-modelized:

[Size] = Array
(
[0] = Array
(
[id] = 2
[name] = S
[position] = 2
[created] =
[modified] =
[ProductsSize] = Array
(
[id] = 248
[product_id] = 4
[size_id] = 2
[stock] = 0
)

)

[1] = Array
(
[id] = 5
[name] = XL
[position] = 5
[created] =
[modified] =
[ProductsSize] = Array
(
[id] = 249
[product_id] = 4
[size_id] = 5
[stock] = 0
)

)

)

But i dont know how to update that stock value, i think the idea is,
like i explained before to get and input field for each row, so i can
specify the stock number for that particular association, in other
words, be able to fill that extra information.

On Sep 18, 12:59 am, VitillO [EMAIL PROTECTED] wrote:
 Hi guys, thanks for your replies.

 Right now, im my 'add' view of products, im getting a multiple select
 for the sizes, where i can select which sizes are available for that
 particular product, thats fine. The problem is that i need a stock
 number for each of this available sizes, so a multiple select wont
 work for me.

 An example would be:

 [ (checkbox) ] Small --- Stock [ input (a number) ]
 [ (checkbox) ] Medium --- Stock [ input (a number) ]
 [ (checkbox) ] Large --- Stock [ input (a number) ]

 So when i hit submit on the form, i can see the selected sizes for
 that product along with the stock value for each one. Thats what i
 need to achieve, but i dont know how to make the associations, neither
 the necessary models for this to work.

 @Adam: how does 'with' parameter works? i cant find the documentation
 for it

 On Sep 17, 11:28 pm, Adam Royle [EMAIL PROTECTED] wrote:

  You can create a model for your habtm association so you can add extra
  fields, etc, using the with key. Something like this...

  class Product extends AppModel {

  ...

  var $hasAndBelongsToMany = array(
      'Size' = array('className' = 'Size',
          'with' = 'ProductsSize', // -- this here, class name can be
  changed
          'joinTable' = 'products_sizes',
          'foreignKey' = 'product_id',
          'associationForeignKey' = 'size_id',
      ),
  );

  }

  class ProductsSize extends AppModel {
      // and here is your joined class!

  }

  Hope that helps,
  Adam

  On Sep 18, 7:07 am, Luiz Poleto [EMAIL PROTECTED] wrote:

   You can create the column stock in the association table.In the form where
   you do the association, you can add a new field for the stock.

   At least that was what i understood from your question...

   Regards,
   Luiz Poleto

   2008/9/17 VitillO [EMAIL PROTECTED]

Hi, i have the following structure for a tshirt online store:

Product HABTM Size
Size HABTM Product

Association table:
products_sizes

The problem is, i need a stocks system.

For example, say i have 50 pieces of S (size) for a particular tshirt,
before using cake i had a column 'stock' in the association table, so
i could retrieve the particular stock of that size, for that product,
but now with cake i dont know how i should make the association.

Any help?

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



Model association question

2008-07-03 Thread jhicks

OK, so I've got two tables: tasks and priorities. Many tasks can share
the same priority. So is this a HABTM relationship?

With HABTM, you usually have a join table but in my situation I don't
need one. I just have a foreign key in my tasks table (priority_id)
which points to the index of the priorities table. What do I do in
this situation? CakePHP is expecting a join table.

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: Model association question

2008-07-03 Thread John David Anderson

I always remember it like this:

If a table contains a foreign key, it's like a little label that  
another object has put on it... i.e. it belongsTo something else.

hth/fwiw,

John


On Jul 3, 2008, at 1:38 PM, Jonathan Snook wrote:


 A priority hasMany tasks.
 A task belongsTo a priority.

 It's a little weird, I know because in English you'd normally say:

 A task has a priority.
 A priority belongs to many tasks.

 And belongsTo is used if:
 A priority has one task.
 A task has one priority.

 At least, that's how I've considered it. (Although I'll gladly be
 corrected).

 On Jul 3, 1:53 pm, jhicks [EMAIL PROTECTED] wrote:
 OK, so I've got two tables: tasks and priorities. Many tasks can  
 share
 the same priority. So is this a HABTM relationship?

 With HABTM, you usually have a join table but in my situation I don't
 need one. I just have a foreign key in my tasks table (priority_id)
 which points to the index of the priorities table. What do I do in
 this situation? CakePHP is expecting a join table.

 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: Model association question

2008-07-03 Thread francky06l

@Jonathan, yes it always a bit confusing the hasOne (in Cake)..
because a Task hasOne priority, no matter if this priority is
shared .. but for cake it'a a belongsTo .. :-) Even after using for
few months  (years)... hasOne always make me think twice (actually I
use it very rarely)..

On Jul 3, 9:56 pm, John David Anderson [EMAIL PROTECTED]
wrote:
 I always remember it like this:

 If a table contains a foreign key, it's like a little label that
 another object has put on it... i.e. it belongsTo something else.

 hth/fwiw,

 John

 On Jul 3, 2008, at 1:38 PM, Jonathan Snook wrote:



  A priority hasMany tasks.
  A task belongsTo a priority.

  It's a little weird, I know because in English you'd normally say:

  A task has a priority.
  A priority belongs to many tasks.

  And belongsTo is used if:
  A priority has one task.
  A task has one priority.

  At least, that's how I've considered it. (Although I'll gladly be
  corrected).

  On Jul 3, 1:53 pm, jhicks [EMAIL PROTECTED] wrote:
  OK, so I've got two tables: tasks and priorities. Many tasks can
  share
  the same priority. So is this a HABTM relationship?

  With HABTM, you usually have a join table but in my situation I don't
  need one. I just have a foreign key in my tasks table (priority_id)
  which points to the index of the priorities table. What do I do in
  this situation? CakePHP is expecting a join table.

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



problem with conditions in model association

2008-07-02 Thread bmgz

Hi All,
I am new to Cake 1.2, (dabbled with 1.? a year ago, but spend more
time with Rails..) I am really getting into this framework, it is
really fun, much better than earlier versions.

I am however stuck with a problem relating to model associations:

Consider the following in my Contract model

...
'Attorney' = array('className' = 'AddressBook',
'foreignKey' = 
'transfer_attorney_id'
'conditions' = 
Attorney.tags LIKE '%attorney%'
),
'BeetleInspector' = array('className' = 'AddressBook',
'foreignKey' = 
'beetle_inspector_id',
'conditions' = 
BeetleInspector.tags LIKE '%fumigation%'
),
'ElecInspector' = array('className' = 'AddressBook',
'foreignKey' = 
'elec_inspector_id',
'conditions' = 
ElecInspector.tags LIKE '%electrical%'
...

Now when I do this in my contracts_controller the Model is returning
ALL the records from AddressBook for each of the vars:

$transferAttorneys = $this-Contract-Attorney-find('list');
$beetleInspectors = 
$this-Contract-BeetleInspector-find('list');
$elecInspectors = $this-Contract-ElecInspector-find('list');
$this-set(compact('beetleInspectors', 'elecInspectors',
'transferAttorneys'));

What am I doing wrong?

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



Custom Model Association Problems

2008-06-16 Thread benjam

I have the following tables with the following fields

territories
-
id
zip_start
zip_end


offices
-
id
zipcode


and I want to associate via hasMany and belongsTo on the following
conditions
(territories hasMany offices) and (offices belongsTo territories):

offices.zipcode BETWEEN territories.zip_start AND territories.zip_end


How can I do this in Cake?
--~--~-~--~~~---~--~~
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: Plugin Model Association Problem

2008-05-25 Thread biesbjerg

Add var $name = 'User';  var $name = 'UserProfile'; as properties in
your models and I think you're golden :-)

On May 24, 10:19 am, francky06l [EMAIL PROTECTED] wrote:
 Can you pass your model definition code ?
 I have the same kind of plugin and not much problems, maybe I declare
 the association in different way.
 I set the plugin name into the className parameter ie :
 belongTo = array('Profile' = array('className' =
 'user.Profile') 

 Wich cake version  are you using ?

 On May 24, 12:05 am, Christopher E. Franklin, Sr.

 [EMAIL PROTECTED] wrote:
  On May 23, 2:49 pm, francky06l [EMAIL PROTECTED] wrote:

   If the user model is in the plugin it should not a problem.. Maybe the
   problem is how you call the find and from where ?

  I do the find in the UsersController::read() function.  It seems to me
  that it is a problem with the association because, when I set 
  $this-User-recursive = -1; I get back just the user.  But, anything else,

  it tries to pull the UserProfile and screws up.

   I guess this is when you try to find user from the application and not
   the plugin ?

  No, I make the call from the users_controller in the plugin.

  Maybe the problem comes from the calling rather than
   the callee ?

  I don't see a problem with $this-User-findById(1); but, like I said,
  if I set recursive to -1 I get the user I want but, not the
  user_profile.  I wanted to get both.

  Alternatively, I can set the UserModel and UserProfileModel both to
  recursive = -1 and just live with the extra calls but, this would be a
  pain if I want to find all users.

  I have also tried declaring different $hasOne and $belongsTo without
  the plugin name like, 'User' instead of 'users.User' but, if I do
  that, it says that it cannot find the database table user_profiles for
  the 'UserProfile' model.

   hth

  Thank you for replying :)
--~--~-~--~~~---~--~~
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: Plugin Model Association Problem

2008-05-24 Thread francky06l

Can you pass your model definition code ?
I have the same kind of plugin and not much problems, maybe I declare
the association in different way.
I set the plugin name into the className parameter ie :
belongTo = array('Profile' = array('className' =
'user.Profile') 

Wich cake version  are you using ?


On May 24, 12:05 am, Christopher E. Franklin, Sr.
[EMAIL PROTECTED] wrote:
 On May 23, 2:49 pm, francky06l [EMAIL PROTECTED] wrote:

  If the user model is in the plugin it should not a problem.. Maybe the
  problem is how you call the find and from where ?

 I do the find in the UsersController::read() function.  It seems to me
 that it is a problem with the association because, when I set 
 $this-User-recursive = -1; I get back just the user.  But, anything else,

 it tries to pull the UserProfile and screws up.

  I guess this is when you try to find user from the application and not
  the plugin ?

 No, I make the call from the users_controller in the plugin.

 Maybe the problem comes from the calling rather than
  the callee ?

 I don't see a problem with $this-User-findById(1); but, like I said,
 if I set recursive to -1 I get the user I want but, not the
 user_profile.  I wanted to get both.

 Alternatively, I can set the UserModel and UserProfileModel both to
 recursive = -1 and just live with the extra calls but, this would be a
 pain if I want to find all users.

 I have also tried declaring different $hasOne and $belongsTo without
 the plugin name like, 'User' instead of 'users.User' but, if I do
 that, it says that it cannot find the database table user_profiles for
 the 'UserProfile' model.

  hth

 Thank you for replying :)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Plugin Model Association Problem

2008-05-23 Thread Christopher E. Franklin, Sr.

Hi great coders,

 I am having a problem trying to get my model associations in a
plugin to come through.

I have a plugin called users and I have a users_controller and a
user_profiles_controller and thier associated models.  Between these
two models, I have them associated as, user has one user profile and
the user profile belongs to a user.

 In my controller, since I want to save the profile information at
the same time as I create the user, I have to declare the $uses
array.  This is fine but, since I am in a plugin, I have to declare
these like so:

public $uses = array('users.User', 'users.UserProfile');  This works
perfectly and I can create a user and a user profile and it saves just
fine.

The problem is when I try to find the user.  In my model association I
have to have:
$belongsTo = 'users.User'; and $hasOne = 'users.UserProfile'; or else
it will say that it cannot find the correct table.

Now, with this set, I get a giant SQL statement with an error:

Query: SELECT `User`.`id`, `User`.`email`, `User`.`password`,
`User`.`group_id`, `User`.`created`, `User`.`updated`,
`User`.`modified`, `users`.`UserProfile`.`id`,
`users`.`UserProfile`.`first_name`, `users`.`UserProfile`.`last_name`,
`users`.`UserProfile`.`address`, `users`.`UserProfile`.`city`,
`users`.`UserProfile`.`state`, `users`.`UserProfile`.`zip`,
`users`.`UserProfile`.`province`, `users`.`UserProfile`.`country`,
`users`.`UserProfile`.`home_telephone`,
`users`.`UserProfile`.`cell_phone`, `users`.`UserProfile`.`fax`,
`users`.`UserProfile`.`user_id` FROM `users` AS `User` LEFT JOIN
`user_profiles` AS `users`.`UserProfile` ON
(`users`.`UserProfile`.user_id = `User`.`id`) WHERE 1 = 1

1064: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '.`UserProfile` ON (`users`.`UserProfile`.user_id = `User`.`id`)
WHERE 1 = 1' at line 1

To me, it looks like the error is in the statement where it says
users.UserProfile ON users.UserProfile.user_id

So, I am at a loss, can't find anything here on the group, or the
tickets and IRC isn't very helpful today.

So, here is the code I have, maybe a second set of eyes will see
something I dont.

Remember, this is in a plugin.


USERS_CONTROLLER - /app/plugins/users/controllers/users_controller.php
---
class UsersController extends UsersAppController {
public $components = array('Auth');
public $uses = array('users.User', 'users.UserProfile');

public function beforeFilter() {
parent::beforeFilter();
$this-Auth-loginAction = '/login';
$this-Auth-logoutAction = '/logout';
$this-Auth-allowedActions = array('index', 'create', 'read',
'update', 'delete');
}

public function index() {

}

public function create() {
if(!empty($this-data)) {
$this-data['User']['password'] = 
$this-Auth-password($this-
data['User']['password']);
$this-User-create($this-data);
$this-User-save($this-data);
$user_id = $this-User-id;
$this-data['UserProfile']['id'] = $user_id;
$this-data['UserProfile']['user_id'] = $user_id;
$this-UserProfile-create($this-data);
$this-UserProfile-save($this-data);
}
$this-set('fields', $this-User-getColumnTypes());
}

public function read($id = 1) {
$this-set('user', $this-User-findById($id));
}

public function update($id = 1) {
$this-set('user', $this-User-findById($id));
}

public function delete() {

}
}

USER_MODEL - /app/plugins/users/models/user.php
---
class User extends UsersAppModel {
public $useDbConfig = 'users';
public $hasOne = 'users.UserProfile';
}

USER_PROFILE_MODEL - /app/plugins/users/models/user_profile.php
--
class UserProfile extends UsersAppModel {
public $useDbConfig = 'users';
public $belongsTo = 'users.User';
}

--~--~-~--~~~---~--~~
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: Plugin Model Association Problem

2008-05-23 Thread francky06l

If the user model is in the plugin it should not a problem.. Maybe the
problem is how you call the find and from where ?

The problem is when I try to find the user.  In my model association I
have to have:

I guess this is when you try to find user from the application and not
the plugin ? Maybe the problem comes from the calling rather than
the callee ?
hth

On May 23, 7:34 pm, Christopher E. Franklin, Sr.
[EMAIL PROTECTED] wrote:
 Hi great coders,

  I am having a problem trying to get my model associations in a
 plugin to come through.

 I have a plugin called users and I have a users_controller and a
 user_profiles_controller and thier associated models.  Between these
 two models, I have them associated as, user has one user profile and
 the user profile belongs to a user.

  In my controller, since I want to save the profile information at
 the same time as I create the user, I have to declare the $uses
 array.  This is fine but, since I am in a plugin, I have to declare
 these like so:

 public $uses = array('users.User', 'users.UserProfile');  This works
 perfectly and I can create a user and a user profile and it saves just
 fine.

 The problem is when I try to find the user.  In my model association I
 have to have:
 $belongsTo = 'users.User'; and $hasOne = 'users.UserProfile'; or else
 it will say that it cannot find the correct table.

 Now, with this set, I get a giant SQL statement with an error:

 Query: SELECT `User`.`id`, `User`.`email`, `User`.`password`,
 `User`.`group_id`, `User`.`created`, `User`.`updated`,
 `User`.`modified`, `users`.`UserProfile`.`id`,
 `users`.`UserProfile`.`first_name`, `users`.`UserProfile`.`last_name`,
 `users`.`UserProfile`.`address`, `users`.`UserProfile`.`city`,
 `users`.`UserProfile`.`state`, `users`.`UserProfile`.`zip`,
 `users`.`UserProfile`.`province`, `users`.`UserProfile`.`country`,
 `users`.`UserProfile`.`home_telephone`,
 `users`.`UserProfile`.`cell_phone`, `users`.`UserProfile`.`fax`,
 `users`.`UserProfile`.`user_id` FROM `users` AS `User` LEFT JOIN
 `user_profiles` AS `users`.`UserProfile` ON
 (`users`.`UserProfile`.user_id = `User`.`id`) WHERE 1 = 1

 1064: You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use
 near '.`UserProfile` ON (`users`.`UserProfile`.user_id = `User`.`id`)
 WHERE 1 = 1' at line 1

 To me, it looks like the error is in the statement where it says
 users.UserProfile ON users.UserProfile.user_id

 So, I am at a loss, can't find anything here on the group, or the
 tickets and IRC isn't very helpful today.

 So, here is the code I have, maybe a second set of eyes will see
 something I dont.

 Remember, this is in a plugin.

 USERS_CONTROLLER - /app/plugins/users/controllers/users_controller.php
 ---
 class UsersController extends UsersAppController {
 public $components = array('Auth');
 public $uses = array('users.User', 'users.UserProfile');

 public function beforeFilter() {
 parent::beforeFilter();
 $this-Auth-loginAction = '/login';
 $this-Auth-logoutAction = '/logout';
 $this-Auth-allowedActions = array('index', 'create', 'read',
 'update', 'delete');
 }

 public function index() {

 }

 public function create() {
 if(!empty($this-data)) {
 $this-data['User']['password'] = 
 $this-Auth-password($this-data['User']['password']);

 $this-User-create($this-data);
 $this-User-save($this-data);
 $user_id = $this-User-id;
 $this-data['UserProfile']['id'] = $user_id;
 $this-data['UserProfile']['user_id'] = $user_id;
 $this-UserProfile-create($this-data);
 $this-UserProfile-save($this-data);
 }
 $this-set('fields', $this-User-getColumnTypes());
 }

 public function read($id = 1) {
 $this-set('user', $this-User-findById($id));
 }

 public function update($id = 1) {
 $this-set('user', $this-User-findById($id));
 }

 public function delete() {

 }

 }

 USER_MODEL - /app/plugins/users/models/user.php
 ---
 class User extends UsersAppModel {
 public $useDbConfig = 'users';
 public $hasOne = 'users.UserProfile';

 }

 USER_PROFILE_MODEL - /app/plugins/users/models/user_profile.php
 --
 class UserProfile extends UsersAppModel {
 public $useDbConfig = 'users';
 public $belongsTo = 'users.User';

 }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php

Re: Plugin Model Association Problem

2008-05-23 Thread Christopher E. Franklin, Sr.

On May 23, 2:49 pm, francky06l [EMAIL PROTECTED] wrote:
 If the user model is in the plugin it should not a problem.. Maybe the
 problem is how you call the find and from where ?

I do the find in the UsersController::read() function.  It seems to me
that it is a problem with the association because, when I set $this-
User-recursive = -1; I get back just the user.  But, anything else,
it tries to pull the UserProfile and screws up.

 I guess this is when you try to find user from the application and not
 the plugin ?

No, I make the call from the users_controller in the plugin.

Maybe the problem comes from the calling rather than
 the callee ?

I don't see a problem with $this-User-findById(1); but, like I said,
if I set recursive to -1 I get the user I want but, not the
user_profile.  I wanted to get both.

Alternatively, I can set the UserModel and UserProfileModel both to
recursive = -1 and just live with the extra calls but, this would be a
pain if I want to find all users.

I have also tried declaring different $hasOne and $belongsTo without
the plugin name like, 'User' instead of 'users.User' but, if I do
that, it says that it cannot find the database table user_profiles for
the 'UserProfile' model.

 hth

Thank you for replying :)
--~--~-~--~~~---~--~~
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: Test Suite v1.2: $useDbConfig problem in model association.

2008-04-17 Thread Defranco

Should I report the fact that $model-setDataSource($dbConfig) do not
affect related models as a bug or as an enhancement?

Actually, if I set

$model-setDataSource('test_suite');

Related model like $model-Model2 will still have  $dbConfig='default'
not $dbConfig='test_suite' as the main model - what looks don't make
sense.

Maybe it should instantiate a new Model2 with $dbConfig='test_suite'
instead of keeping relations of models between databases.

Is it a bug or should report only as an enhancement?
--~--~-~--~~~---~--~~
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: Test Suite v1.2: $useDbConfig problem in model association.

2008-04-10 Thread releod

thanks for posting that - I was running into the same problems, all is
well now. According to the passing tests :)

On Mar 20, 5:20 pm, Defranco [EMAIL PROTECTED] wrote:
 Hi again,

 Please discard the code from previous post, it has a lot of bugs.

 This is working better:

 __
 //app_model.php:

 function __construct($id = false, $table = null, $ds = null){

 parent::__construct($id, $table, $ds);

 //This need to be placed after parent::__construct();
 $_dbConfig_test = 'test_suite';
 if ( $this-useDbConfig == $_dbConfig_test)
 $this-setDataSource_recursively($_dbConfig_test);
 }

 function setDataSource_recursively ($dbConfig, $recursive = 5){

 $sub_models = array();

 if ($this-useDbConfig !== $dbConfig)
 $this-setDataSource($dbConfig);

 if ($recursive = 0){
 foreach ($this-tableToModel as $tableToModel)
 $sub_models[] = $tableToModel;

 foreach ( $sub_models as $model){

 if (isset($this-{$model})){
 
 $this-{$model}-setDataSource_recursively($dbConfig, --
 $recursive);
 }
 }
 }
 }
 _
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model Association

2008-02-25 Thread Darkman_dd

Hello, i have a question: i have a model named admin where the
admins of the site can write an article, edit it, delete it etc. It's
assosiated with model section so every article must belong to a
section.

How can i make a model articles that doesn't have a database
connected to it but it can just use the fields from the other model to
show them to the visitor of the site? Let's say it will be the frond-
end of the site. When sb is going to the site i want it to go to /
articles/ (i know how to change it from routes.php) and show to the
user the all the published articles, e.g. sorted by their section. I'm
giving this example so i can help you understand what i want to do.

The reason that i don't want to use the admin model to view to
visitors the articles is that i don't want them to have any access to
the admin model (it will be password protected), for security reasons.

I just want to have a model to publish the articles (which were
written in admin model) to the frontpage so visitors can view them
there. I'm trying to do this with the code below. Is it the right
approach or i need to think something else?

The Admin model:
class Admin extends AppModel
{
var $name = 'Admin';
var $belongsTo = array ('Section' = array(
'className' = 'Section',
'conditions'= null,
'order'= null,
'foreignKey'='section_id')
);
var $hasMany = array ('Article' = array(
'className' = 'Article',
'conditions'= null,
'order'= null,
'foreignKey'='admin_id')
);
}

The Section model:
class Section extends AppModel
{
var $name = 'Section';
var $hasMany = array (
'Admin' = array(
'className' = 'Admin',
'conditions'= null,
'order'= null,
'foreignKey'='section_id'),

'Article' = array(
'className' = 'Article',
'conditions'= null,
'order'= null,
'foreignKey'='section_id')
);
}

The articles model:
class Article extends AppModel
{
var $name = 'Article';
var $useTable = false;
var $belongsTo = array (

'Section' = array(
'className' = 'Section',
'conditions'= null,
'order'= null,
'foreignKey'='section_id'),

'Admin' = array(
'className' = 'Admin',
'conditions'= null,
'order'= null,
'foreignKey'='admin_id')
);
}


I did the above but i don't think it's the right thing to do..

Thank you for your time

--~--~-~--~~~---~--~~
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: Model Association Query....stumped

2008-02-08 Thread EchoChargen

I've done the following:
Clipranking Model:
function findClipByRank($site_id){
return $this-query(SELECT Clipranking.rank, 
Clipranking.site_id,
Clipranking.required, Clip.id, Clip.name, Clip.length FROM
cliprankings AS Clipranking, clips AS Clip WHERE Clipranking.site_id =
$site_id AND Clipranking.clip_id = Clip.id);
}

And calling in my controller works fine: $clip = $this-Site-
Clipranking-findClipByRank($id);

In my short experience with Cake, it seems that there would be a more
Cake-ish way to accomplish this.   I'm a noob here so, it's probably
obvious.

Thanks,
Jeremy
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model Association Query....stumped

2008-02-07 Thread EchoChargen

All -
I've been using Mariano Iglesias Bindable behavior with 1.2 beta to
nice effect, but I've run into a query I can't figure out.  Here's
what I have:
Team hasMany Clip
Team hasMany Site
Site hasMany Clipranking

A Site can play any of the Clips available in their Team in whatever
ranked order they wish.  The Clipranking table contains a field 'rank'
and 'clip_id'.  Clipranking and Clip are not related (at least not
now...).  In my Sites controller I want to retrieve all the
Cliprankings and get the Clip data that corresponds to the 'clip_id'.
I can't seem to get a query or on the fly BindModel() that will get me
what I want.
I guess I'm obtuse.   I've never done a HBTM relationship before, and
maybe that's what I need?  I'm open to any suggestions or noob
sledgehammering for not seeing it.

Much obliged,
Jeremy
--~--~-~--~~~---~--~~
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: Model Association without Foreign key (Cake 1.18)

2008-02-06 Thread Bo-oz

It's 1.19 btw... but think that won't mather much.

On Feb 6, 10:16 am, Bo-oz [EMAIL PROTECTED] wrote:
 Hi,

 I would like to enrich a model with data from another model. However
 they are not directly related. The value that needs to be fetched from
 the other model lies within a certain time-range.

 I've searched the groups and have found that you should be able to
 indicate that the foreignKey = false... but still I cannot get it to
 work!

 I have the following model for Pirce

 class Price extends AppModel {
 var $hasOne = array('Vatrate'=
 array('conditions'
   ='1=1',
 
 'foreignKey'=false)
 );

 }

 The idea should be to finally make a condition which bounds the date,
 so that I know which VAT-rate should be taken.

 Any thoughts on how to use a model association (if this is possible)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model Association without Foreign key (Cake 1.18)

2008-02-06 Thread Bo-oz

Hi,

I would like to enrich a model with data from another model. However
they are not directly related. The value that needs to be fetched from
the other model lies within a certain time-range.

I've searched the groups and have found that you should be able to
indicate that the foreignKey = false... but still I cannot get it to
work!

I have the following model for Pirce

class Price extends AppModel {
var $hasOne = array('Vatrate'=
array('conditions'  
='1=1',

'foreignKey'=false)
);
}

The idea should be to finally make a condition which bounds the date,
so that I know which VAT-rate should be taken.

Any thoughts on how to use a model association (if this is possible)

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



  1   2   >