Re: Reverse relations?

2009-01-01 Thread WebbedIT

Not that it always makes logical sense, but in this case I do agree
that a user or person belongs to their country as they are an
inhabitant of that country.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Reverse relations?

2008-12-31 Thread gearvOsh

I know how to do relations for foreign keys, but I cannot figure out
how to do this.

In my users table, I have a column called state_id and country_id. I
tried a hasOne country but that does not work. It looks for a user_id
on the Country table that matches the user id, I need it the other way
around. I need the country_id on the user table to match the id on the
country table. How would I go about this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Reverse relations?

2008-12-31 Thread Bernardo Vieira

User belongsTo Country?

gearvOsh wrote:
 I know how to do relations for foreign keys, but I cannot figure out
 how to do this.

 In my users table, I have a column called state_id and country_id. I
 tried a hasOne country but that does not work. It looks for a user_id
 on the Country table that matches the user id, I need it the other way
 around. I need the country_id on the user table to match the id on the
 country table. How would I go about this?
 

   


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



Re: Reverse relations?

2008-12-31 Thread WebbedIT

 User belongsTo Country?

Yip .. the rule of thumb is that the table containing the foreign key
belongsTo the other table.
--~--~-~--~~~---~--~~
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: Reverse relations?

2008-12-31 Thread gearvOsh

I could of sworn I tried that and it didn't work, I must have changed
the foreign_key. Anyways that worked.

Yeah I was also thinking in my system... is that a user is top level
and he has many different parts. A user is not necessarily part of a
country, but I guess ill have to do it that way.
--~--~-~--~~~---~--~~
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: Unbind Reverse Relations in Recursive Queries

2008-03-03 Thread sabkaraja

cool. its working :)

Does it support conditions from related models?

eg: I want to load the chapters for a specific user only?
$subjects = $this-Subject-find('all',
array('conditions'='Subject.enabled=1',
'restrict'=array(
'Topic'=array(
'restrict'=array(
'Chapter'=array(
'restrict'=array(
'User'=array('conditions'='User.id=30')
)));

How to make this work? Or Am I asking for sky :)

thanks all


On Mar 3, 12:59 pm, Matias Lespiau [EMAIL PROTECTED] wrote:
 On Mon, Mar 3, 2008 at 5:38 AM, sabkaraja [EMAIL PROTECTED] wrote:

  Hi

 Hi,







  I have 3 models: Subject, Topic  Chapter

  Subject  hasMany  Topics  Topic  belongsTo  Subject
  Topic  hasMany  Chapters  Chapter  belongsTo  Topic
  User  HABTM  Chapter

  I am trying to do a recursive query ($this-Subject-
  findAll('Subject.enabled=1'); ) to find out all the subjects  topics
   chapters (and if needed users), I get results (copied only relevant
  bits) like the following:

  Array
  (
     [Subject] = Array
         (
             [id] = 1
             ...
             ...

         )

     [Topic] = Array
         (
             [0] = Array
                 (
                     [id] = 1
                     [subject_id] = 1
                     ...
                     ...
                     ...
                     [Subject] = Array
                         (
                             [id] = 1
                             ...
                             ...
                         )

                     [Chapter] = Array
                         (
                             [0] = Array
                                 (
                                     [id] = 1
                                     [topic_id] = 1
                                     ...
                                     ...
                                 )

                         )

                 )
     }
  }

  I want only a forward relationship records. that is: subject  Topics
   chapters  users. I dont want Topics  Subject query. This adds
  considerable overhead to a findAll query.
  How can I avoid that?

 I think $this-Subject-Topic-unbindModel(array('belongsTo' = 'Subject'));
 before the findAll should do the trick. If you want an easy way of handling
 model bindings, try out Mariano Iglesia's Bindable 
 Behavior:http://bakery.cakephp.org/articles/view/bindable-behavior-control-you...

 --
 Matias Lespiauhttp://www.gignus.com/- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Unbind Reverse Relations in Recursive Queries

2008-03-02 Thread sabkaraja

Hi

I have 3 models: Subject, Topic  Chapter

Subject  hasMany  Topics  Topic  belongsTo  Subject
Topic  hasMany  Chapters  Chapter  belongsTo  Topic
User  HABTM  Chapter

I am trying to do a recursive query ($this-Subject-
findAll('Subject.enabled=1'); ) to find out all the subjects  topics
 chapters (and if needed users), I get results (copied only relevant
bits) like the following:

Array
(
[Subject] = Array
(
[id] = 1
...
...

)

[Topic] = Array
(
[0] = Array
(
[id] = 1
[subject_id] = 1
...
...
...
[Subject] = Array
(
[id] = 1
...
...
)

[Chapter] = Array
(
[0] = Array
(
[id] = 1
[topic_id] = 1
...
...
)

)

)
}
}

I want only a forward relationship records. that is: subject  Topics
 chapters  users. I dont want Topics  Subject query. This adds
considerable overhead to a findAll query.
How can I avoid that?

thanks

--~--~-~--~~~---~--~~
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: Unbind Reverse Relations in Recursive Queries

2008-03-02 Thread websta*

If your using 1.2 definitely check out the wicked little behavior that is
bindable:

http://bakery.cakephp.org/articles/view/bindable-behavior-control-your-model
-bindings



-Original Message-
From: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of sabkaraja
Sent: Monday, 3 March 2008 8:38 p.m.
To: Cake PHP
Subject: Unbind Reverse Relations in Recursive Queries


Hi

I have 3 models: Subject, Topic  Chapter

Subject  hasMany  Topics  Topic  belongsTo  Subject
Topic  hasMany  Chapters  Chapter  belongsTo  Topic
User  HABTM  Chapter

I am trying to do a recursive query ($this-Subject-
findAll('Subject.enabled=1'); ) to find out all the subjects  topics
 chapters (and if needed users), I get results (copied only relevant
bits) like the following:

Array
(
[Subject] = Array
(
[id] = 1
...
...

)

[Topic] = Array
(
[0] = Array
(
[id] = 1
[subject_id] = 1
...
...
...
[Subject] = Array
(
[id] = 1
...
...
)

[Chapter] = Array
(
[0] = Array
(
[id] = 1
[topic_id] = 1
...
...
)

)

)
}
}

I want only a forward relationship records. that is: subject  Topics
 chapters  users. I dont want Topics  Subject query. This adds
considerable overhead to a findAll query.
How can I avoid that?

thanks




__ NOD32 2915 (20080303) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com



--~--~-~--~~~---~--~~
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: Unbind Reverse Relations in Recursive Queries

2008-03-02 Thread Matias Lespiau
On Mon, Mar 3, 2008 at 5:38 AM, sabkaraja [EMAIL PROTECTED] wrote:


 Hi


Hi,



 I have 3 models: Subject, Topic  Chapter

 Subject  hasMany  Topics  Topic  belongsTo  Subject
 Topic  hasMany  Chapters  Chapter  belongsTo  Topic
 User  HABTM  Chapter

 I am trying to do a recursive query ($this-Subject-
 findAll('Subject.enabled=1'); ) to find out all the subjects  topics
  chapters (and if needed users), I get results (copied only relevant
 bits) like the following:

 Array
 (
[Subject] = Array
(
[id] = 1
...
...

)

[Topic] = Array
(
[0] = Array
(
[id] = 1
[subject_id] = 1
...
...
...
[Subject] = Array
(
[id] = 1
...
...
)

[Chapter] = Array
(
[0] = Array
(
[id] = 1
[topic_id] = 1
...
...
)

)

)
}
 }

 I want only a forward relationship records. that is: subject  Topics
  chapters  users. I dont want Topics  Subject query. This adds
 considerable overhead to a findAll query.
 How can I avoid that?


I think $this-Subject-Topic-unbindModel(array('belongsTo' = 'Subject'));
before the findAll should do the trick. If you want an easy way of handling
model bindings, try out Mariano Iglesia's Bindable Behavior:
http://bakery.cakephp.org/articles/view/bindable-behavior-control-your-model-bindings


-- 
Matias Lespiau
http://www.gignus.com/

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