Re: Problem with retrieving data with relationships

2009-05-25 Thread Bryan Paddock
ahhh awesome thanks man... still getting to grips with cakephp here!


On Sat, May 23, 2009 at 8:45 PM, Ricky Paz ricky...@gmail.com wrote:


 Hi,

 You have to use belongsTo and hasMany for 1-n relationship, and not
 hasOne and hasMany. In your PropertiesModel, put $belongsTo =
 'Seller, and, inside SellerModel, put hasMany = 'Property'.
 


--~--~-~--~~~---~--~~
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 retrieving data with relationships

2009-05-23 Thread number9

I'm fairly new myself so you will have to bear with me here!

How do you reference fields in your view? There may be a problem there
if that is wrong. Have you baked the controllers/views?

I think the problem is probably your recursive setting, try adding
this line to your controller:

$this-Property-recursive = 2;

When you are pulling in related data you need it set to two in some
cases depending on the data you are trying to output. If debug is not
already set to 2 (in the config file) set it to 2 so you can see the
SQL queries that are being run.

On May 22, 10:38 pm, Bryan Paddock bryanpadd...@gmail.com wrote:
 Hi all,
 Just started learning cakephp last week so a bit scratchy and still
 learning...

 There are two tables in question here:

 property - stores rows of properties
 seller - stores sellers of the properties.

 - one property can only have one seller
 - one seller can have many properties

 property model has its hasone definition:

   // one property has one seller
   var $hasOne = array(
     'Seller' = array(
       'className'    = 'Seller',
       'foreignKey'    = 'id'
     )
   );

 seller model has its hasmany defintion:

   // one seller can have any number of favourites and properties
   var $hasMany = array(
     'Favourite' = array(
       'className'     = 'Favourite',
       'foreignKey'    = 'seller_id',
       'dependent'= true
     ),
     'Property' = array(
       'className' = 'Property',
       'foreignKey' = 'seller_id'
     )
   );

 ignore the favourites table for now...

 property table contains 'seller_id'

 property table
 
 id
 seller_id
 x

 seller table
 ---
 id
 xx

 (I do have $useTable defined in each model to ensure table names are
 correct)

 In my browse function of the propertiescontroller I have the standard code:

     $this-pageTitle = 'Browse All Properties';
     $this-paginate['limit'] = 25;
     $data = $this-paginate('Property');
     $this-set('properties', $data);

 It returns the properties but blank seller information.. it has the full
 seller array with all the database fields but no values for any of them...

 Can anyone shed some light on this?

 I'm quite stuck here!

 - Bryan
--~--~-~--~~~---~--~~
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 retrieving data with relationships

2009-05-23 Thread Ricky Paz

Hi,

You have to use belongsTo and hasMany for 1-n relationship, and not
hasOne and hasMany. In your PropertiesModel, put $belongsTo =
'Seller, and, inside SellerModel, put hasMany = 'Property'.
--~--~-~--~~~---~--~~
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 retrieving data with relationships

2009-05-22 Thread Bryan Paddock
Hi all,
Just started learning cakephp last week so a bit scratchy and still
learning...

There are two tables in question here:

property - stores rows of properties
seller - stores sellers of the properties.

- one property can only have one seller
- one seller can have many properties

property model has its hasone definition:

  // one property has one seller
  var $hasOne = array(
'Seller' = array(
  'className'= 'Seller',
  'foreignKey'= 'id'
)
  );

seller model has its hasmany defintion:

  // one seller can have any number of favourites and properties
  var $hasMany = array(
'Favourite' = array(
  'className' = 'Favourite',
  'foreignKey'= 'seller_id',
  'dependent'= true
),
'Property' = array(
  'className' = 'Property',
  'foreignKey' = 'seller_id'
)
  );

ignore the favourites table for now...

property table contains 'seller_id'

property table

id
seller_id
x

seller table
---
id
xx

(I do have $useTable defined in each model to ensure table names are
correct)

In my browse function of the propertiescontroller I have the standard code:

$this-pageTitle = 'Browse All Properties';
$this-paginate['limit'] = 25;
$data = $this-paginate('Property');
$this-set('properties', $data);

It returns the properties but blank seller information.. it has the full
seller array with all the database fields but no values for any of them...

Can anyone shed some light on this?

I'm quite stuck here!

- Bryan

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