Skip to content

Instantly share code, notes, and snippets.

@dator-zz
Created January 9, 2012 13:23
Show Gist options
  • Save dator-zz/1582913 to your computer and use it in GitHub Desktop.
Save dator-zz/1582913 to your computer and use it in GitHub Desktop.
3 tables: Product, Category, ProductCategory
A product has many categories and a category can belong to many products.
The category objet is nestedset(via doctrine behavior) with a parent, and a position.
I need to be able to manage these categories (up/down/delete/new/edit)
I need to be able to add many categories to a product.
AFAIK, when a category (cat1) has a parent (cat0), and you want to add cat1 to a product, you need to add cat0 too.
Is there a simple way to handle these recommandation?
Thanks a lot ^â
@ludofleury
Copy link

Why do you want to add cat0 too ? If the cat1 belong to cat0, adding a product to cat1 mean it belong to cat0 also, you don't need to add it manually ?

@dator-zz
Copy link
Author

dator-zz commented Jan 9, 2012

According to my recent test in database, if i add product1 to cat1, this doesnt work as expected, it's need cat0 too (the parent).

Maybe i'm wrong and when you save your object in database it handle it well ^^

Do you have some widget/validator to handle manytomany nestedset association? :)

@ludofleury
Copy link

In fact the context isn't clear to me : 2 logics are in "collision" ?
The nested tree "business logic" apply to the productcategory ? Is this assert true : "If a product is linked to a category, every parent category are also "defacto" linked to the product ?"

  • Are we talking about doctrine 1.2 ?
  • What's your query need ? Showing all categories including the parent on the product page AND fetching all product for a given category all right ?
  • could you gist your schema ?
  • I may have some old code about that (for backend purpose) yet it's not Open Source oriented (mean : maybe a bit dirty/specific), I would be sure it match your need before sharing it with you.

@dator-zz
Copy link
Author

dator-zz commented Jan 9, 2012

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment