Hey all,

Just to butt in here, this is how I do it:

*Hypothetical situation:*
*Entities:*
PhoneNumber
Company
Person
*Relations:*
Companies can have many PhoneNumbers
Persons can have many PhoneNumbers
The same PhoneNumber can belong to multiple Companies
The same PhoneNumber can belong to multiple Persons
The same PhoneNumber can belong to Company(s) and Person(s) at the same
time.
*Tables:*
phone_number (phone_id, ...)
company (company_id, ...)
person (person_id, ...)
company_phone (company_id, phone_id)
person_phone (person_id, phone_id)
*Mappers:
*
CompanyMapper
- find($id)
PersonMapper
- find($id)
PhoneMapper
- find($id)
- findByCompany($companyId) [does a join on phone_number and company_phone]
- findByPerson($personId) [does a join on phone_number and person_phone]

My notes:
I keep the findBy* in the PhoneMapper, because I do object hydration of the
Phone object, so it makes sense to do these queries here.

FYI, I use the AbstractDbMapper from ZfcBase. It works great for doing your
own object management.

Hope this helps.

Cheers,

Michael Gooden


On 22 May 2013 01:54, tonystamp <[email protected]> wrote:

> ok, so you have one mapper that communicates with two seperate tables (even
> if the second table just contains, for instance, 2 columns (foreign keys))?
> So i'm assuming that is two seperate TableGateway instances? Or you just
> have an adapter with custom sql queries?
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/zf2-one-many-to-many-relationships-tp4659910p4660088.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [email protected]
> Info: http://framework.zend.com/archives
> Unsubscribe: [email protected]
>
>
>

Reply via email to