This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Simple One-to-many with doctrine
Simple One-to-many with doctrine [message #95766] Fri, 19 March 2010 10:37 Go to next message
symfonyParis  is currently offline symfonyParis
Messages: 13
Registered: February 2010
Junior Member
Hi symfonians,
This is simple, but i can't do a simple one-to many relation in my schema.yml. I want a user to have many profiles. When editing a user, a profile should be a mandatory multiple select. What is the best way to schematize it in my schema.yml with doctrine?
Thanks a lot for any help.
Re: Simple One-to-many with doctrine [message #95782 is a reply to message #95766 ] Fri, 19 March 2010 12:17 Go to previous messageGo to next message
rudenich  is currently offline rudenich
Messages: 3
Registered: December 2009
Junior Member
What about this??

User:
  columns:
    login:
      type: string(255)
    password:
      type: string(255)
      
      
Profile:
  columns:
    user_id: 
      type: integer(4)
    field1:
      type: string(255)
    field2:
      type: string(255)
    field3:
      type: string(255)
  relations:
    user:
      class: User
      local: user_id
      foreign: id
      type: one
      foreignType: many
      foreignAlias: profiles
Re: Simple One-to-many with doctrine [message #95795 is a reply to message #95782 ] Fri, 19 March 2010 14:15 Go to previous messageGo to next message
symfonyParis  is currently offline symfonyParis
Messages: 13
Registered: February 2010
Junior Member

I got this


SQLSTATE[HY000]: General error: 1005 Can't create table 'project.#sql-e70_3e'
(errno: 150). Failing Query: "ALTER TABLE profile ADD CONSTRAINT profile_user_id
_user_id FOREIGN KEY (user_id) REFERENCES user(id)". Failing Query: ALTER TABLE
profile ADD CONSTRAINT profile_user_id_user_id FOREIGN KEY (user_id) REFERENCES
user(id)

when i execute :

php symfony doctrine:build --all --and-load --no-confirmation
Re: Simple One-to-many with doctrine [message #95799 is a reply to message #95795 ] Fri, 19 March 2010 14:57 Go to previous messageGo to next message
symfonyParis  is currently offline symfonyParis
Messages: 13
Registered: February 2010
Junior Member
Ok, i remove the integer lenght (4) in Profile:columns:user_id and doctrine:build worked
but it's not what i wanted, i think i have to reverse user and profile, to get on user edition the selection of profiles and not users selection on the profile edition, i'll try..

Also, i don't have the possibility of multiple selection. Is there any way to put something in schema.yml to have it???

Thanks again


Ps: attachment with two forms

  • Attachment: screen.JPG
    (Size: 14.62KB, Downloaded 62 time(s))

Re: Simple One-to-many with doctrine [message #95959 is a reply to message #95766 ] Mon, 22 March 2010 14:15 Go to previous messageGo to next message
symfonyParis  is currently offline symfonyParis
Messages: 13
Registered: February 2010
Junior Member
Nothing to do, i always get :

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

when i save my company :

Category:
columns:
name:
type: string(255)

Company:
columns:
category_id:
type: integer
field1:
type: string(255)
relations:
Category:
alias: Category
foreignType: many
foreignAlias: Companies
onDelete: cascade

Please, somenone help
Re: Simple One-to-many with doctrine [message #96121 is a reply to message #95766 ] Wed, 24 March 2010 14:18 Go to previous message
abo3ans  is currently offline abo3ans
Messages: 21
Registered: February 2010
Junior Member
if you want one company has many categories try this

Company:
columns:
name: { type: string(255) }

Category:
columns:
company_id: { type: integer(4), notnull: true }
field: { type: string(255), notnull: true }
relations:
Company: { local: company_id, foreign: id, onDelete:CASCADE }

but this is the simple way try it with the true fields which you want to use

try it and tell me
Previous Topic:[solved] support arabic in I18N hwo to
Next Topic:[SOLVED] sfDoctrineGuardPlugin - Error during data-load
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software