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


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


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


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





 



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



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



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



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



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



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



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



Re: Model Association without Foreign key (Cake 1.18)

2008-02-06 Thread Bo-oz

I was afraid of that... I've read some other reply's by you in another
thread, and based on that, I was already expecting that this could not
be done. Would be great functionality though.

On Feb 6, 10:37 am, AD7six [EMAIL PROTECTED] wrote:
 On Feb 6, 10:23 am, Bo-oz [EMAIL PROTECTED] wrote:

  It's 1.19 btw... but think that won't mather much.

 I think you need (a v recent) 1.2 for that to work unless you do it
 yourself

 hth,

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



On Feb 6, 10:23 am, Bo-oz [EMAIL PROTECTED] wrote:
 It's 1.19 btw... but think that won't mather much.

I think you need (a v recent) 1.2 for that to work unless you do it
yourself

hth,

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

2007-12-26 Thread lordG

This does also tend to be related to my post on naming conventions in
http://groups.google.com/group/cake-php/browse_thread/thread/35318b04d8a93144/fcffe0e17499f82c?lnk=stq=#fcffe0e17499f82c

if the class name and the $name value are to be the same, why is this
not the case with Controllers? Is this not inconsistent?
--~--~-~--~~~---~--~~
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 'limit' not working

2007-12-08 Thread zonium

Did you try turning on debug mode and see how the SQL statement looks
like? Try running the sql statement manually and you should be able to
track where the problem is.
Zonium


On Dec 7, 5:30 pm, sanderken [EMAIL PROTECTED] wrote:
 People looking for the answer to  defining limit row in oracle  :

 in the model , use the
 'conditions' = ' WHERE ROWNUM = 3 '
 option.

 Limit is the implementation in mySQL.
 Hope this helps someone...

 On 8 dec, 01:53, sanderken [EMAIL PROTECTED] wrote:

  Maybe I should mention I'm using oracle for DBMS.

  On 7 dec, 21:54, sanderken [EMAIL PROTECTED] wrote:

   Hey,

   I defined a user (named Gebruiker in my native language ) model
   where when I call a $this-find() , needs to retrieve only a limited
   amount of related information.

   When I add the 'limit' = '10' to the association info, it doesn't
   work. For example: I call
  $gebruiker = $this-find(
   array(Gebruiker.id = $gebruikerid)
   );
in the model and it retrieves 11 'kommentaars'.

   Does anyone know why this happens? I searched the internet for model
   information, and even the example 
   onhttp://manual.cakephp.org/chapter/modelsshowthesame way of doing
   this. But it works in their example and not in my situation ;)

   Does anyone know how to solve this problem?

   Thanks,

   Here's the code:

   class Gebruiker extends AppModel
   {
   var $name = 'Gebruiker';

   var $hasMany = array(
   'Blog' = array(
   'className' = 'Blog',
   'order' = 'Blog.created DESC',
   'limit' = '10',
   'foreignKey' = 'gebruiker_id',

   ),
   'Kommentaar' = array(
   'className' = 'Kommentaar',
   'order' = 'Kommentaar.created DESC',
   'limit' = '5',
   'foreignKey' = 'gebruiker_id'
   ),
   'Message_sent' = array(
   'className' = 'Message',
   'order'= 'Message_sent.created DESC',
   'limit'= '10',
   'foreignKey'= 'sender_id',
   ),
   'Message_received' = array(
   'className' = 'Message',
   'order'=
   'Message_received.created DESC',
   'limit'   = '10',
   'foreignKey'= 'receiver_id',
   )
   );
!-- Model logic here --

   }
--~--~-~--~~~---~--~~
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 'limit' not working

2007-12-07 Thread sanderken

People looking for the answer to  defining limit row in oracle  :

in the model , use the
'conditions' = ' WHERE ROWNUM = 3 '
option.

Limit is the implementation in mySQL.
Hope this helps someone...

On 8 dec, 01:53, sanderken [EMAIL PROTECTED] wrote:
 Maybe I should mention I'm using oracle for DBMS.

 On 7 dec, 21:54, sanderken [EMAIL PROTECTED] wrote:

  Hey,

  I defined a user (named Gebruiker in my native language ) model
  where when I call a $this-find() , needs to retrieve only a limited
  amount of related information.

  When I add the 'limit' = '10' to the association info, it doesn't
  work. For example: I call
 $gebruiker = $this-find(
  array(Gebruiker.id = $gebruikerid)
  );
   in the model and it retrieves 11 'kommentaars'.

  Does anyone know why this happens? I searched the internet for model
  information, and even the example 
  onhttp://manual.cakephp.org/chapter/modelsshowthe same way of doing
  this. But it works in their example and not in my situation ;)

  Does anyone know how to solve this problem?

  Thanks,

  Here's the code:

  class Gebruiker extends AppModel
  {
  var $name = 'Gebruiker';

  var $hasMany = array(
  'Blog' = array(
  'className' = 'Blog',
  'order' = 'Blog.created DESC',
  'limit' = '10',
  'foreignKey' = 'gebruiker_id',

  ),
  'Kommentaar' = array(
  'className' = 'Kommentaar',
  'order' = 'Kommentaar.created DESC',
  'limit' = '5',
  'foreignKey' = 'gebruiker_id'
  ),
  'Message_sent' = array(
  'className' = 'Message',
  'order'= 'Message_sent.created DESC',
  'limit'= '10',
  'foreignKey'= 'sender_id',
  ),
  'Message_received' = array(
  'className' = 'Message',
  'order'=
  'Message_received.created DESC',
  'limit'   = '10',
  'foreignKey'= 'receiver_id',
  )
  );
   !-- Model logic here --

  }

--~--~-~--~~~---~--~~
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 'limit' not working

2007-12-07 Thread sanderken

Maybe I should mention I'm using oracle for DBMS.

On 7 dec, 21:54, sanderken [EMAIL PROTECTED] wrote:
 Hey,

 I defined a user (named Gebruiker in my native language ) model
 where when I call a $this-find() , needs to retrieve only a limited
 amount of related information.

 When I add the 'limit' = '10' to the association info, it doesn't
 work. For example: I call
$gebruiker = $this-find(
 array(Gebruiker.id = $gebruikerid)
 );
  in the model and it retrieves 11 'kommentaars'.

 Does anyone know why this happens? I searched the internet for model
 information, and even the example 
 onhttp://manual.cakephp.org/chapter/modelsshow the same way of doing
 this. But it works in their example and not in my situation ;)

 Does anyone know how to solve this problem?

 Thanks,

 Here's the code:

 class Gebruiker extends AppModel
 {
 var $name = 'Gebruiker';

 var $hasMany = array(
 'Blog' = array(
 'className' = 'Blog',
 'order' = 'Blog.created DESC',
 'limit' = '10',
 'foreignKey' = 'gebruiker_id',

 ),
 'Kommentaar' = array(
 'className' = 'Kommentaar',
 'order' = 'Kommentaar.created DESC',
 'limit' = '5',
 'foreignKey' = 'gebruiker_id'
 ),
 'Message_sent' = array(
 'className' = 'Message',
 'order'= 'Message_sent.created DESC',
 'limit'= '10',
 'foreignKey'= 'sender_id',
 ),
 'Message_received' = array(
 'className' = 'Message',
 'order'=
 'Message_received.created DESC',
 'limit'   = '10',
 'foreignKey'= 'receiver_id',
 )
 );
  !-- Model logic here --

 }

--~--~-~--~~~---~--~~
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 (again)

2006-10-24 Thread Ismael S. Kafeltz

Maybe this can help you:

http://wiki.cakephp.org/docs:understanding_associations


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



Re: Model association issue

2006-09-13 Thread AD7six

Hi Brian,

You can´t create 2 associations with the same name. You can't say a
user HasOne Venue and User HABTM Venue - if you don´t give you
associations unique names the data for both will get mixed together
(with confusing results as you have seen).

Let me clarify what that means before you say but I need those
associations ;)

Try something like this:
?php
class User extends AppModel
{
var $name = 'User';

var $hasOne = array('MainFan' = // Changed
array('className'= 'Fan',
  'conditions'   = '',
  'order'= '',
  'dependent'=  true,
  'foreignKey'   = 'user_id'
),
'MainArtist' = // Changed
array('className'= 'Artist',
  'conditions'   = '',
  'order'= '',
  'dependent'=  true,
  'foreignKey'   = 'user_id'
),
'MainVenue' = // Changed
array('className'= 'Venue',
  'conditions'   = '',
  'order'= '',
  'dependent'=  true,
  'foreignKey'   = 'user_id'
),
'MainPromoter' = // Changed
array('className'= 'Promoter',
  'conditions'   = '',
  'order'= '',
  'dependent'=  true,
  'foreignKey'   = 'user_id'
),
  );
var $hasAndBelongsToMany =
array('Fan','Artist','Venue','Promoter'); // unchanged
}

If the hasOne is to specify some special relationship, I think that in
1.2 you have/will have the possibility to add fields to your join table
such that you could then have only a HABTM with one of the defined
relationships having the type Main (or whatever is the actual
meaining of the hasOne as defined here).

Rather than dribble on, after renaming your associations - does that
work?

HTH,

AD7six
PS. this is all based upon looking at your debug data and glancing at
the source - so it could be wrong.


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



Re: Model association issue

2006-09-13 Thread Brian French

Thank you! That fixed my problem perfectly!

AD7six wrote:
 Hi Brian,

 You can´t create 2 associations with the same name. You can't say a
 user HasOne Venue and User HABTM Venue - if you don´t give you
 associations unique names the data for both will get mixed together
 (with confusing results as you have seen).

 Let me clarify what that means before you say but I need those
 associations ;)

 Try something like this:
 ?php
 class User extends AppModel
 {
 var $name = 'User';

 var $hasOne = array('MainFan' = // Changed
 array('className'= 'Fan',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
 'MainArtist' = // Changed
 array('className'= 'Artist',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
 'MainVenue' = // Changed
 array('className'= 'Venue',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
 'MainPromoter' = // Changed
 array('className'= 'Promoter',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
   );
 var $hasAndBelongsToMany =
 array('Fan','Artist','Venue','Promoter'); // unchanged
 }

 If the hasOne is to specify some special relationship, I think that in
 1.2 you have/will have the possibility to add fields to your join table
 such that you could then have only a HABTM with one of the defined
 relationships having the type Main (or whatever is the actual
 meaining of the hasOne as defined here).

 Rather than dribble on, after renaming your associations - does that
 work?

 HTH,

 AD7six
 PS. this is all based upon looking at your debug data and glancing at
 the source - so it could be wrong.


 


   


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



Re: Model association issue

2006-09-12 Thread Brian French




Could someone help me with this?

Brian French wrote:

  I should have elaborated more. When you view that link then go to view a 
particular user:
http://www.myclubbersguide.com/users/view/6
The associations dont seem to be working and i am now getting a php error.

(i have a view method in the users controller, but i commented it out so 
the scaffolding can do its thing)

Brian

AD7six wrote:
  
  
Hi Brian,

I took a peek at your link: I dont quite understand what the problem
is, can you elaborate?

The sql at the foot of the page shows that sql queries are being
executed for your associations. If you look at the user "test" you can
see that there are results for each association type.

Where is this coming from: array ( [User] = Array ( [id] = 2 [name]
= Fan User [login] = f etc.

if you have created a method named view in your users controller, there
will be no scaffolding for that action.

cheers,

AD7six
PS. the method pr() gives you shorter debugging code and easier to read
output.




  

  
  




  


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





Re: Model association issue

2006-09-11 Thread Brian French

bump

Brian French wrote:
 I am having trouble associating the multiple models i have with each other.

 I have a 'User' that hasOne 'Fan','Artist','Venue','Promoter'.
 The 'User' also hasAndBelongsToMany of the same ones (like he can 
 subscribe to them as well as be one/all of them).

 I am using the scaffolding to view the associations with them. The 
 associations are being added ok but when i view the user, the 
 associations aren't being picked up. Here are the 'User' model and the 
 'Artist' model (the fan, artist, venue and promoter models all look the 
 same).

 What am i doing wrong?

 (i can supply a url of the scaffolding with the debug set to 2 if you 
 would like)


 ?php
 class Artist extends AppModel
 {
 var $name = 'Artist';
 var $belongsTo = 'User';
 var $hasAndBelongsToMany = 'User';
 }
 ?

 ?php
 class User extends AppModel
 {
 var $name = 'User';

 var $hasOne = array('Fan' =
 array('className'= 'Fan',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
 'Artist' =
 array('className'= 'Artist',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
 'Venue' =
 array('className'= 'Venue',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
 'Promoter' =
 array('className'= 'Promoter',
   'conditions'   = '',
   'order'= '',
   'dependent'=  true,
   'foreignKey'   = 'user_id'
 ),
   );
 var $hasAndBelongsToMany = array('Fan','Artist','Venue','Promoter');
 }
 ?





 

   

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



Re: Model association issue

2006-09-11 Thread Chris Hartjes

On 9/8/06, Brian French [EMAIL PROTECTED] wrote:

 I am having trouble associating the multiple models i have with each other.

 I have a 'User' that hasOne 'Fan','Artist','Venue','Promoter'.
 The 'User' also hasAndBelongsToMany of the same ones (like he can
 subscribe to them as well as be one/all of them).

 I am using the scaffolding to view the associations with them. The
 associations are being added ok but when i view the user, the
 associations aren't being picked up. Here are the 'User' model and the
 'Artist' model (the fan, artist, venue and promoter models all look the
 same).

 What am i doing wrong?


I've never used the scaffolding before, but can you show the code that
you think is pulling out the User information?  Also, the database
output (showing all the queries) would be helpfull.  I wonder if the
scaffolding is setting the recursive stuff to -1 and simply showing
User records only...

-- 
Chris Hartjes

The greatest inefficiencies come from solving problems you will never have.
-- Rasmus Lerdorf

@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

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



Re: Model association issue

2006-09-11 Thread Brian French




Scaffolding can display this for you, it's a great tool!

You can view the output here: http://www.myclubbersguide.com/users
It contains the queries being used as well as the print_r() of the
object(s).
The code for the models was in the first email/post in this thread. As
far as i understand it, scaffolding is recursive.

Thank you for your help,
Brian French

Chris Hartjes wrote:

  On 9/8/06, Brian French [EMAIL PROTECTED] wrote:
  
  
I am having trouble associating the multiple models i have with each other.

I have a 'User' that hasOne 'Fan','Artist','Venue','Promoter'.
The 'User' also hasAndBelongsToMany of the same ones (like he can
subscribe to them as well as be one/all of them).

I am using the scaffolding to view the associations with them. The
associations are being added ok but when i view the user, the
associations aren't being picked up. Here are the 'User' model and the
'Artist' model (the fan, artist, venue and promoter models all look the
same).

What am i doing wrong?


  
  
I've never used the scaffolding before, but can you show the code that
you think is pulling out the User information?  Also, the database
output (showing all the queries) would be helpfull.  I wonder if the
scaffolding is setting the recursive stuff to -1 and simply showing
User records only...

  


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





Re: Model association issue

2006-09-11 Thread AD7six

Hi Brian,

I took a peek at your link: I don´t quite understand what the problem
is, can you elaborate?

The sql at the foot of the page shows that sql queries are being
executed for your associations. If you look at the user test you can
see that there are results for each association type.

Where is this coming from: array ( [User] = Array ( [id] = 2 [name]
= Fan User [login] = f etc.

if you have created a method named view in your users controller, there
will be no scaffolding for that action.

cheers,

AD7six
PS. the method pr() gives you shorter debugging code and easier to read
output.


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



Re: Model association issue

2006-09-11 Thread Brian French

I should have elaborated more. When you view that link then go to view a 
particular user:
http://www.myclubbersguide.com/users/view/6
The associations dont seem to be working and i am now getting a php error.

(i have a view method in the users controller, but i commented it out so 
the scaffolding can do its thing)

Brian

AD7six wrote:
 Hi Brian,

 I took a peek at your link: I don´t quite understand what the problem
 is, can you elaborate?

 The sql at the foot of the page shows that sql queries are being
 executed for your associations. If you look at the user test you can
 see that there are results for each association type.

 Where is this coming from: array ( [User] = Array ( [id] = 2 [name]
 = Fan User [login] = f etc.

 if you have created a method named view in your users controller, there
 will be no scaffolding for that action.

 cheers,

 AD7six
 PS. the method pr() gives you shorter debugging code and easier to read
 output.


 


   


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



Re: Model association

2006-05-09 Thread roberts.sean

I'm having a similar problem simply trying to add comments to posts.
I've tried to get a list of comments that would be associated with a
single post by adding

$this-set('comments', $this-Comment-findAll(WHERE post_id =
'$id'));

to the view() function under posts_controller.php but that line returns
Fatal error: Call to a member function on a non-object.  I don't
fully understand how to go about viewing and manipulating data like
comments that are fully dependent on posts.  I shouldn't have to set up
individual controllers and views for them because I don't want users to
have to go to /comments to view them.

Can anyone give a little insight into this as well as the original
question?


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



Re: Model association

2006-05-09 Thread John Anderson

Gotta use model assocations - it makes this sort of thing so much nicer.

http://manual.cakephp.org/chapter/6

Looks like your Comment belongsTo Post, and probably Post hasMany  
Comment.

Give the manual a look, and let me know if you have questions on it.

-- J

On May 9, 2006, at 1:47 PM, roberts.sean wrote:


 I'm having a similar problem simply trying to add comments to posts.
 I've tried to get a list of comments that would be associated with a
 single post by adding

 $this-set('comments', $this-Comment-findAll(WHERE post_id =
 '$id'));

 to the view() function under posts_controller.php but that line  
 returns
 Fatal error: Call to a member function on a non-object.  I don't
 fully understand how to go about viewing and manipulating data like
 comments that are fully dependent on posts.  I shouldn't have to  
 set up
 individual controllers and views for them because I don't want  
 users to
 have to go to /comments to view them.

 Can anyone give a little insight into this as well as the original
 question?


 


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



Re: Model association

2006-05-09 Thread roberts.sean

I read through the manual in one go last week, totally forgot I had to
set up the associations myself.

Now that I've done it I can't believe how simple it is.  I'm REALLY
starting to like this whole baking thing.  Thanks John!


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