Sorry Ronan, I was treating category as a 1:1 relationship. Just
replace my getCategoryId() with getCategoryIds()...the rest should
still be applicable.

On Jun 20, 2:47 pm, Greg Stevens <[EMAIL PROTECTED]> wrote:
> Hey Ronan,
>
> AI have some thoughts on #1. It is the OO way to create the
> beanCategory and go beanProduct.setCategory(beanCategory), however
> this doesn't translate well to the database. What I have been thinking
> is that the product bean would have not just 1 attribute for Category,
> but 2. One that represents the category's id and another that
> represent's the category object.
>
> Product
> -------------------------------------------------
> categoryId : int
> category : Category
> -------------------------------------------------
> getCategoryId() : int
> setCategoryId(int) : void
> getCategory() : Category
> setCategory(Category) : void
> -------------------------------------------------
>
> This is where I break some patterns out there, but I like to have a
> slightly smart bean so I would end up having it so that when
> Product.getCategory() is ran, it returns
> CategoryDAO.findById(getCategoryId()). The only problem is this means
> that the CategoryDAO would need to be injected into the Product. Would
> it make any sense at all to just inject a ProductsDAO into the
> product, inject the CategoryDAO into the ProductsDAO and then have
> ProductsDAO.getCategory(productBean) return CategoryDAO.findById(...)?
> Is this where the Gateway may be useful?
>
> On Jun 20, 12:49 pm, Ronan Lucio <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I have two doubts hitting my mind:
>
> > 1) What is the best way to populate foreign keys into a bean?
>
> >     Supposing I have a class Product.
> >     Each product has a Category.
>
> >     What is the right way:
>
> >     beanProduct = serviceProduct.getBean();
> >     beanProduct.setName( "It's name" );
> >     beanProduct.setCategory( 1 );
>
> >     or
>
> >     beanCategory = serviceCategory.getBean( 1 );
>
> >     beanProduct = serviceProduct.getBean();
> >     beanProduct.setName( "It's name" );
> >     beanProduct.setCategory( beanCatebory );
>
> >     or neither?
>
> > 2) In CF community we use to talk about DAOs and Gateways but it doesn't
> > seem a widely used pattern.
> >     What is the best usage? Have just one DAO as Row Data Gateway and
> > Table Data Gateway or use DAO as RDG and Gateways as TDG?
>
> > Thanks,
> > Ronan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to