tags:

views:

368

answers:

1

where can i learn more abt creating database markup in yaml and data fixtures.

i followed a tutorial and they create a relationship like so: under relations in both User and Car. my qn is why is 'type: many' in Car. can i have it in User instead (just curious)?

abt data types. different database have different database support. i thought that in MySQL (InnoDB as used here) integer shld be tinyint(x), bigint(x), int(x) ... or string shld be varchar not string? isit not strict what i shld use here?

options:
  type: INNODB
  collate: utf8_general_ci
  charset: utf8

User:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    name: string(300)
    email: string(300)
    phone: string(9)
    car_id: integer
  relations: 
    Car: 
      local: car_id
      foreign: id
Car:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    brand: string(300)
  relations:
    Users:
      class: User
      foreign: car_id
      local: id
      type: many

UPDATE 1

  1. "it is only necessary to specify the relationship on the end where the foreign key exists" in my example, that will be? do they mean the FK table (car) or the FK column (user)?

  2. i dont see TEXT data type, is that clob (Character Large OBject)? – iceangel89 0 secs ago [delete this comment]

  3. what is foreignAlias? is there a alias too?

UPDATE 2

this will be abit long, i just wish to clarify some of the code examples in the Doctrine YAML Schema Files docs page. focus on the relationships section -> in // comments

User:
  columns:
    username:
      type: string(255)
    password:
      type: string(255)
    contact_id:
      type: integer
  relations:
    Contact:
      class: Contact // if the table is named Contact, class will be Contact also?
      local: contact_id 
      foreign: id
      foreignAlias: User // whats alias for? 
      foreignType: one // one contact ... to ...
      type: one // one user?

Contact:
  columns:
    first_name:
      type: string(255)
    last_name:
      type: string(255)
    phone:
      type: string(255)
    email:
      type: string(255)
    address:
      type: string(255)
  relations:
    User:
      class: User
      local: id
      foreign: contact_id
      foreignAlias: Contact
      foreignType: one
      type: one

regarding the many to many example, what does the following mean?

attributes:
  export: all
  validate: true

tableName: group_table

refClass: GroupUser
+1  A: 

where can i learn more abt creating database markup in yaml and data fixtures.

Doctrine manual, “YAML schema files” and “Data Fixtures” chapters.

can i have it in User instead (just curious)?

Yes, but this section will be called foreignType then. Here, an example:

User:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    name: string(300)
    email: string(300)
    phone: string(9)
    car_id: integer
  relations: 
    Car: 
      local: car_id
      foreign: id
      foreignType: many

abt data types...

Well, Doctrine column types and database column types are “slightly” different. Just compare list of Doctrine column types and, say, MySQL's one.

develop7
regarding relationship type. in your example, shldn't foreignType be one? hmm ... (1 user -> 1 car, 1 car -> many user). when i specify relations: car: foreignType: one, what does that mean? one user? – iceangel89 1 min ago [delete this comment]. + see update 1
iceangel89
No, it shouldn't, because it is **foreign**
develop7
hmm... ok when u say "foreignType: many" in this case (your code), will it mean (1 user to) many car or (1 car to) many user. same with foreignAlias, what does it mean? or whats it used for?
iceangel89
`foreignType` is declared at `User` side, and means exactly *many Cars*. That's why it's *foreign*.`foreignAlias: User` means we get User instance out of Contact's one via `$contact->User`
develop7
so just to conclude, in your above answer, User: relations: Car: foreignType: many. it means many cars to one user?
iceangel89
hmm i guess it means 1 car to many users? i kinda confused with these foreign thingy
iceangel89