Battling (My Own) Idiocy

a.k.a. do everything wrong the first time just to get it out of the way

Archive for February, 2010

Forms for N:M Related Models With Additional Relationships

Posted by halestock on February 25, 2010

Although Symfony and Doctrine are very intuitive when it comes to detecting many-to-many(M:N) relationships and generating the relevant forms, there was one situation I encountered where I found myself looking for an alternative solution. Take, for instance, the following Doctrine schema for a simple project management system:

# config/doctrine/schema.yml

Project:
  columns:
    name: { type: string(255), notnull: true, unique: true }
  relations:
    Users:
      refClass: ProjectUser
      class:    User
      local:    project_id
      foreign:  user_id

User:
  columns:
    username: { type: string(255), notnull: true, unique: true }
  relations:
    Projects:
      refClass: ProjectUser
      class:    Project
      local:    user_id
      foreign:  project_id

Role:
  columns:
    name: { type: string(255), notnull: true, unique: true }

ProjectUser:
  columns:
    user_id:      { type: integer, notnull: true, primary: true }
    project_id:   { type: integer, notnull: true, primary: true }
    user_role_id: { type: integer, notnull: true }
  relations:
    Role:
      class:   Role
      local:   user_role_id
      foreign: id
    Project:
      class: Project
      local: project_id
      foreign: id
    User:
      class: User
      local: user_id
      foreign: id

Read the rest of this entry »

Posted in Symfony | Tagged: , | Leave a Comment »

Understanding Permissions/Credentials with SfDoctrineGuardPlugin

Posted by halestock on February 8, 2010

When it comes time to secure an application, be it for user management or protecting an application’s internals, Symfony provides an excellent framework to handle the process. This can be extended with the use of the official SfDoctrineGuardPlugin, which provides a foundation to manage users, permissions and groups through the Doctrine ORM.

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 11 Comments »

Implementing a Nested Set (part three)

Posted by halestock on February 4, 2010

In the final post of this series, I’ll add some relatively simple formatting to the nested set list to make it much more intuitive and readable. I’ll also show how to correctly implement the deleting of items, which I forgot to explain before (and is definitely something that needs to be added to make this usable).

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 18 Comments »

Implementing a Nested Set (part two)

Posted by halestock on February 4, 2010

In my last post, I used a custom widget and validator to represent a nested set in Doctrine. Of course, they aren’t much use without actually being implemented, so in this post I will show how to go about creating them.

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 11 Comments »

Implementing a Nested Set (part one)

Posted by halestock on February 3, 2010

While representing data in a tree structure is normally straightforward, implementing it in a relational database is somewhat of a struggle. The standard way of representing hierarchical data in a relational database is using what’s called a nested set, which (luckily) Doctrine has a built-in behavior for.

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 23 Comments »

 
Follow

Get every new post delivered to your Inbox.