Does sfGuardUser table have a primary key?
I'm new to Symfony and Doctrine and am writing a web app. I added the sfDoctrineGuardPlugin to my project. When I open the schema.yml file for the plugin I see this:
sfGuardUser:
actAs: [Timestampable]
columns:
first_name: string(255)
last_name: string(255)
email_address:
type: string(255)
notnull: true
unique: true
username:
type: string(128)
notnull: true
unique: true
algorithm:
type: string(128)
default: sha1
notnull: 开发者_如何学编程true
salt: string(128)
password: string(128)
is_guest:
type: boolean
default: 0
is_active:
type: boolean
default: 1
is_super_admin:
type: boolean
default: false
last_login:
type: timestamp
indexes:
is_active_idx:
fields: [is_active]
relations:
Groups:
class: sfGuardGroup
local: user_id
foreign: group_id
refClass: sfGuardUserGroup
foreignAlias: Users
Permissions:
class: sfGuardPermission
local: user_id
foreign: permission_id
refClass: sfGuardUserPermission
foreignAlias: Users
Does this schema generate a table with a primary key (and if so, how do I access it)? I've looked online and most of the pages that cover the schema for sfGuardUser display an id column that is the primary key. What am I missing? Thanks.
Yes, it's id
, accessed as sfGuardUser u --> u.id, as in...
$user = Doctrine::getTable('sfGuardUser')->findOneById(55);
or...
$q = Doctrine_Query::create()
->select('u.*')
->from('sfGuardUser u')
->where('u.id = ?', 55);
$q->execute();
I think somewhere in the Doctrine documentation it says that Doctrine auto-generates an "id" primary key if one isn't declared in the YAML file. It used to be declared explicity in the sfGuardPlugin schema but as of Symfony 1.4.8 (I think), it's just not written.
One thing to watch out for is that elsewhere in your schema, you need to make sure that you declare the same numeric type for the other end of the foreign key relationship or otherwise it'll throw an error. I think it's just type: integer
that you need.
If no primary key is given, doctrine will create an id fieldwith type bigint and with a primary key.
精彩评论