1:N and 1:1 using link table

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

1:N and 1:1 using link table

Esteban A. Maringolo
Is it possible to have a 1:N (ToManyMapping) using a link table, and
also a 1:1 mapping using the same link table?

Ej:
Let's suppose I have a list of Supervisors and a list of Stores.
One supervisor can have serveral stores (1:N).

On the other side, each store can have only one supervisor.

I tried using the descriptors described below, but I'm getting an
error with error:
'Joins should go to the table(s) associated with the reference class
of the mapping' in OneToOneMapping(RelationshipMapping)>>#validate:

I couldn't find an example for this in the tests.



On the Supervisor descriptor I have:
(aDescriptor newMapping: ToManyMapping)
  attributeName: #stores;
  referenceClass: Store;
  usesLinkTable: true;
  collectionType: Set;
  beExclusive;
  join: (Join
    from: (table fieldNamed: 'id')
    to: (storesLinkTable fieldNamed: 'supervisor_id')).

On the Stores descriptor I have:
(aDescriptor newMapping: OneToOneMapping)
  attributeName: #supervisor;
  referenceClass: StoreSupervisor;
  join: (Join
    from: (table fieldNamed: 'id')
    to:  (storesLinkTable fieldNamed: 'store_id')).


If I remove the join: I get the error:
 'Cannot automatically determine join, too many constraints found.'

Because the table Store also have other 1:1 references to the class
Supervisor (with an explicit join), of which StoreSupervisor is a
subclass, and Supervisor is the root of a filtered type resolver.


Regards!

Esteban A. Maringolo

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 1:N and 1:1 using link table

Esteban A. Maringolo
Well... working or not, there is flaw in such design.

The link table should have a single PK only on store_id, otherwise the
table could hold N:M relations instead of 1:N relations, and if there
was a way of having a 1:1 relation back using the link table, such
relation wouldn't be resolved because of several rows in the link
table.

Other than that I don't know if it still could work.

Regards!

Esteban A. Maringolo


2014-10-22 12:01 GMT-03:00 Esteban A. Maringolo <[hidden email]>:

> Is it possible to have a 1:N (ToManyMapping) using a link table, and
> also a 1:1 mapping using the same link table?
>
> Ej:
> Let's suppose I have a list of Supervisors and a list of Stores.
> One supervisor can have serveral stores (1:N).
>
> On the other side, each store can have only one supervisor.
>
> I tried using the descriptors described below, but I'm getting an
> error with error:
> 'Joins should go to the table(s) associated with the reference class
> of the mapping' in OneToOneMapping(RelationshipMapping)>>#validate:
>
> I couldn't find an example for this in the tests.
>
>
>
> On the Supervisor descriptor I have:
> (aDescriptor newMapping: ToManyMapping)
>   attributeName: #stores;
>   referenceClass: Store;
>   usesLinkTable: true;
>   collectionType: Set;
>   beExclusive;
>   join: (Join
>     from: (table fieldNamed: 'id')
>     to: (storesLinkTable fieldNamed: 'supervisor_id')).
>
> On the Stores descriptor I have:
> (aDescriptor newMapping: OneToOneMapping)
>   attributeName: #supervisor;
>   referenceClass: StoreSupervisor;
>   join: (Join
>     from: (table fieldNamed: 'id')
>     to:  (storesLinkTable fieldNamed: 'store_id')).
>
>
> If I remove the join: I get the error:
>  'Cannot automatically determine join, too many constraints found.'
>
> Because the table Store also have other 1:1 references to the class
> Supervisor (with an explicit join), of which StoreSupervisor is a
> subclass, and Supervisor is the root of a filtered type resolver.
>
>
> Regards!
>
> Esteban A. Maringolo

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 1:N and 1:1 using link table

Alan Knight-2
You have to tell the 1:1 mapping to use a link table as well. 

On Wed Oct 22 2014 at 8:14:09 AM Esteban A. Maringolo <[hidden email]> wrote:
Well... working or not, there is flaw in such design.

The link table should have a single PK only on store_id, otherwise the
table could hold N:M relations instead of 1:N relations, and if there
was a way of having a 1:1 relation back using the link table, such
relation wouldn't be resolved because of several rows in the link
table.

Other than that I don't know if it still could work.

Regards!

Esteban A. Maringolo


2014-10-22 12:01 GMT-03:00 Esteban A. Maringolo <[hidden email]>:
> Is it possible to have a 1:N (ToManyMapping) using a link table, and
> also a 1:1 mapping using the same link table?
>
> Ej:
> Let's suppose I have a list of Supervisors and a list of Stores.
> One supervisor can have serveral stores (1:N).
>
> On the other side, each store can have only one supervisor.
>
> I tried using the descriptors described below, but I'm getting an
> error with error:
> 'Joins should go to the table(s) associated with the reference class
> of the mapping' in OneToOneMapping(RelationshipMapping)>>#validate:
>
> I couldn't find an example for this in the tests.
>
>
>
> On the Supervisor descriptor I have:
> (aDescriptor newMapping: ToManyMapping)
>   attributeName: #stores;
>   referenceClass: Store;
>   usesLinkTable: true;
>   collectionType: Set;
>   beExclusive;
>   join: (Join
>     from: (table fieldNamed: 'id')
>     to: (storesLinkTable fieldNamed: 'supervisor_id')).
>
> On the Stores descriptor I have:
> (aDescriptor newMapping: OneToOneMapping)
>   attributeName: #supervisor;
>   referenceClass: StoreSupervisor;
>   join: (Join
>     from: (table fieldNamed: 'id')
>     to:  (storesLinkTable fieldNamed: 'store_id')).
>
>
> If I remove the join: I get the error:
>  'Cannot automatically determine join, too many constraints found.'
>
> Because the table Store also have other 1:1 references to the class
> Supervisor (with an explicit join), of which StoreSupervisor is a
> subclass, and Supervisor is the root of a filtered type resolver.
>
>
> Regards!
>
> Esteban A. Maringolo

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.