tags:

views:

291

answers:

1

I'm totally at a loss with the following schema.yml:

JobeetCategory:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }

JobeetJob:
  actAs: { Timestampable: ~ }
  columns:
    category_id:  { type: integer, notnull: true }
    type:         { type: string(255) }
    company:      { type: string(255), notnull: true }
    logo:         { type: string(255) }
    url:          { type: string(255) }
    position:     { type: string(255), notnull: true }
    location:     { type: string(255), notnull: true }
    description:  { type: string(4000), notnull: true }
    how_to_apply: { type: string(4000), notnull: true }
    token:        { type: string(255), notnull: true, unique: true }
    is_public:    { type: boolean, notnull: true, default: 1 }
    is_activated: { type: boolean, notnull: true, default: 0 }
    email:        { type: string(255), notnull: true }
    expires_at:   { type: timestamp, notnull: true }
  relations:
    JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs } 

JobeetAffiliate:
  actAs: { Timestampable: ~ }
  columns:
    url:       { type: string(255), notnull: true }
    email:     { type: string(255), notnull: true, unique: true }
    token:     { type: string(255), notnull: true }
    is_active: { type: boolean, notnull: true, default: 0 }
  relations:
    JobeetCategories:
      class: JobeetCategory
      refClass: JobeetCategoryAffiliate
      local: affiliate_id
      foreign: category_id
      foreignAlias: JobeetAffiliates

JobeetCategoryAffiliate:
  columns:
    category_id:  { type: integer, primary: true }
    affiliate_id: { type: integer, primary: true }
  relations:
    JobeetCategory:  { onDelete: CASCADE, local: category_id, foreign: id }
    JobeetAffiliate: { onDelete: CASCADE, local: affiliate_id, foreign: id }

And how to define it correctly?

+3  A: 

Short and sweet:

Behaviors ('actAs') are, as the name suggests, a way to define the behaviour (sp - sorry, British ;-)) of a model. I'd say the most commonly-used are "Timestampable" (which adds created and updated fields to your table and updates these automatically) and "SoftDelete" (which adds a deleted_at column, timestamped if the record is "deleted" instead of actually removing the record).

More info here - http://www.doctrine-project.org/documentation/manual/1_2/en/behaviors

Relations - relating models to other models. Eg a blog post is likely to have many comments - a one-to-many relationship between the post and comments. In the Jobeet example above, a Job belongs to a Category.

and again, more info here - http://www.doctrine-project.org/documentation/manual/1_2/en/defining-models#relationships

But, as @Marko commented above, start with the documentation :-) The page from the Symfony docs which you've got the schema from even has a picture to explain the relationships between the tables... :-)

richsage