Thanks. Working now except on my forms the drop-down lists display the
id # instead of the field.
for example the drop down for Organization displays id 3 and id 4
instead of the Organization Name.
Here is all my code:
organization model
<?
class organization extends AppModel {
var $name = 'Organization';
var $hasMany = array('User');
}
?>
type model
<?
class type extends AppModel {
var $name = 'Type';
var $hasMany = array('User');
}
?>
user model
<?
class user extends AppModel{
var $name = 'User';
var $belongsTo = array('Organization','Type');
}
?>
organizations_controller
<?
class OrganizationsController extends AppController {
var $name = 'Organization';
var $scaffold;
}
?>
types_controller
<?
class typesController extends AppController {
var $name = 'Type';
var $scaffold;
}
?>
users_controller
<?
class UsersController extends AppController {
var $name = 'User';
var $scaffold;
}
?>
On Aug 17, 9:22 pm, brian <[email protected]> wrote:
> Heh, normally, having the link wouldn't do much good; you'd need to
> provide your find() code. But:
>
> SELECT `User`.`id`, `User`.`type_id`, `User`.`organizations_id`, ...
>
> It looks to me like you created a column named 'organizations_id'
> rather than 'organization_id'. The latter is what you want. Cake
> picked it up when it issued 'DESCRIBE users' in order to get the table
> schema. So, your code is probably good and you just need to modify the
> column name.
>
>
>
> On Mon, Aug 17, 2009 at 4:08 PM, Magua<[email protected]> wrote:
>
> > URL
> >http://beta.openaccessinc.com/users
>
> > On Aug 17, 3:46 pm, Magua <[email protected]> wrote:
> >> I am now generating the following error when i load users
> >> Warning (512): SQL Error: 1054: Unknown column 'User.organization_id'
> >> in 'on clause' [CORE/cake/libs/model/datasources/dbo_source.php, line
> >> 524]
>
> >> Here are my models
>
> >> organizaton.php
> >> <?
> >> class organization extends AppModel {
> >> var $name = 'organization';
> >> var $hasMany = array('User');
> >> }
> >> ?>
>
> >> type.php
> >> <?
> >> class type extends AppModel {
> >> var $name = 'Type';
> >> var $hasMany = array('User');}
>
> >> ?>
>
> >> user.php
> >> <?
> >> class user extends AppModel {
> >> var $name = 'User';
> >> var $belongsTo = array('Type','Organization');
>
> >> }
>
> >> ?>
>
> >> On Aug 17, 3:18 pm, brian <[email protected]> wrote:
>
> >> > Just add the model to $belongsTo array.
>
> >> > User:
> >> > var $belongsTo = array('Type', 'Organization');
>
> >> > Organization:
> >> > var $hasMany = array('User');
>
> >> > On Mon, Aug 17, 2009 at 3:04 PM, Magua<[email protected]> wrote:
>
> >> > > Thanks I have it working now.
> >> > > But i now need a another $belongs to declaration in my "user.php"
> >> > > model.
> >> > > How does cake handle this.
>
> >> > > For example i have now added an "organizations" table with the
> >> > > following fields
> >> > > id, name
>
> >> > > and i have added the following field to the "users" table.
> >> > > organization_id
>
> >> > > Each user can only Belong To one organization.
>
> >> > > How is this done
>
> >> > > On Aug 17, 1:30 pm, brian <[email protected]> wrote:
> >> > >> You forgot the "array" part:
>
> >> > >> var $hasOne = array('Type');
>
> >> > >> BUT you probably want:
>
> >> > >> var $belongsTo = array('Type');
>
> >> > >> Type:
> >> > >> var $hasMany = array('User');
>
> >> > >> If you used Group instead of Type it would make more sense.
>
> >> > >> On Mon, Aug 17, 2009 at 12:52 PM, Magua<[email protected]> wrote:
>
> >> > >> > Please note I am a very GREEN newby to MVC programing.
>
> >> > >> > I have 2 tables.
> >> > >> > 1.> users
> >> > >> > Fields: id, user, type_id
> >> > >> > 2.> types
> >> > >> > Fields: id, type
>
> >> > >> > Each user can have only 1 "type" and each "type" can have many
> >> > >> > "users".
> >> > >> > I have created the following models.
>
> >> > >> > user.php
> >> > >> > <?
> >> > >> > class User extends AppModel {
> >> > >> > var $name = 'User';
> >> > >> > var $hasOne = 'Type';
> >> > >> > }
> >> > >> > ?>
> >> > >> > The above model generates this error.
> >> > >> > Parse error: syntax error, unexpected '(' in
> >> > >> > /var/www/beta/htdocs/app/
> >> > >> > models/kind.php on line 4
>
> >> > >> > type.php
> >> > >> > <?
> >> > >> > class type extends AppModel {
> >> > >> > var $name = 'type';
> >> > >> > var $hasMany = ('user');
> >> > >> > }
> >> > >> > ?>
> >> > >> > The type error generates this error.
> >> > >> > Parse error: syntax error, unexpected '(' in
> >> > >> > /var/www/beta/htdocs/app/
> >> > >> > models/type.php on line 4
>
> >> > >> > What am i doing wrong? Is this not a hasOne Relationship.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---