any idea?
On 19 mar, 13:39, dandreta <[EMAIL PROTECTED]> wrote:
> If I add the relation in the model Person :
>
> var $belongsTo = array('Profile' => array('className' => 'Profile',
> 'foreignKey'
> => 'profile_id',
> 'order' =>
> 'Profile.level ASC',
> ),
> );
>
> And this function in persons controller.
> function test(){
> debug( $this->Person->findAll() );
>
> }
>
> I obtain an array where each person has one profile and persons are
> correctly ordered by profile.level.
>
> But the problem of the initial post continues.
> This is the sql statement that generates the error(1054: Unknown
> column 'Profile.level' in 'order clause'):
>
> SELECT `Person`.`id`, `Person`.`name`, `Person`.`profile_id`,
> `PersonsProject`.`id`, `PersonsProject`.`person_id`,
> `PersonsProject`.`project_id`, `PersonsProject`.`priority` FROM
> `persons` AS `Person` JOIN `persons_projects` AS `PersonsProject` ON
> (`PersonsProject`.`project_id` IN (15, 16, 17) AND
> `PersonsProject`.`person_id` = `Person`.`id`) ORDER BY
> `PersonsProject`.`priority` ASC, `Profile`.`level` ASC
>
> On 19 mar, 10:58, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Check your sql debug. Is the Profile table part of the query?
> > If not you may not have set recursive high enough for it to be
> > included.
>
> > A test to see if the association is set right can be done easily by
> > adding a test method to the persons controller.
> > function test(){
> > debug( $this->Person->findAll() );}
>
> > you will get an ugly dump but is should contain an (empty) array for
> > Profile for each Person.
>
> > @Lisa:
> > I think you can use the extra fields in the way attempted here. They
> > are available in the sql-query but are not loaded as part of the data
> > returned.
>
> > On Mar 18, 5:25 pm, dandreta <[EMAIL PROTECTED]> wrote:
>
> > > Thanks for yor response martin. I have tried to add the
> > > relation(Person belongsTo Profile) in the model Person but the
> > > error(Unknown colum) appears.
> > > any help?
> > > Regards
>
> > > On 18 mar, 13:45, "[EMAIL PROTECTED]"
>
> > > <[EMAIL PROTECTED]> wrote:
> > > > You have: Profile hasOne Person but not any reference the other way.
> > > > To get to the profile from Project to Person to Profile you also need
> > > > the Person to belong to the Profile.
>
> > > > Note on personal preference (i.e. not essential to getting things
> > > > working):
> > > > I prefer a person to have a profile and a profile to belong to a
> > > > person unless you need the fk in that table for a reason. It really
> > > > amounts to the same, it just sounds better when thinking about it.
>
> > > > On Mar 18, 12:31 pm, dandreta <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi!
> > > > > My doubt is the following one.
> > > > > I have 3 tables with their respective models (Project, Person,
> > > > > Profile).
> > > > > A person has one profile and a profile corresponds to only one person.
> > > > > On the other hand, a person can realize several projects and a project
> > > > > can be realized by several persons. Summarizing, the tables and
> > > > > relations of my models are these:
>
> > > > > TABLE PROFILES
> > > > > id, level
> > > > > TABLE PERSONS
> > > > > id, name, profile_id
> > > > > TABLE PROJECTS
> > > > > id, name
> > > > > TABLE PERSONS_PROJECTS
> > > > > id, person_id, project_id, priority (int extra field)
>
> > > > > MODEL PROFILE
> > > > > var $hasOne = array('Person' => array('className' => 'Person',
> > > > > 'foreignKey' =>
> > > > > 'profile_id')
> > > > > );
>
> > > > > MODEL PERSON
> > > > > var $hasAndBelongsToMany = array(
> > > > > 'Project' => array('className' => 'Project',
> > > > > 'joinTable' => 'persons_projects',
> > > > > 'foreignKey' => 'person_id',
> > > > > 'associationForeignKey' => 'project_id')
> > > > > );
>
> > > > > MODEL PROJECT
> > > > > var $hasAndBelongsToMany = array(
> > > > > 'Person' => array('className' => 'Person',
> > > > > 'joinTable' => 'persons_projects',
> > > > > 'foreignKey' => 'project_id',
> > > > > 'associationForeignKey' => 'person_id')
> > > > > );
>
> > > > > With all that, in projects_ controller I have a function that shows a
> > > > > project and its list of relationed persons. The problem is that I want
> > > > > that this list of persons is ordered (1º) by the field priority of the
> > > > > persons_projects table and (2º) by the field level of the profiles
> > > > > table. I achieve the first thing, adding in the relation of the
> > > > > Project model
>
> > > > > $hasAndBelongsToMany= array('Person' => array('className' => 'Person',
> > > > > ...............
> > > > > 'order' => PersonsProject.priority ASC)
> > > > > );
>
> > > > > But, the problem appears ordering by the level field of the Profile
> > > > > table, because if I change the previous code for:
> > > > > 'Order' => ' PersonsProject.priority ASC, Profile.level ASC '
>
> > > > > This error appears:
> > > > > SQL error: 1054: Unknown column 'Profile.level' in ' order clause '
> > > > > How can I solve it? I hope you can help me.
> > > > > I use Cakephp 1.2.
> > > > > Thanks and regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---