On Mon, Oct 26, 2009 at 9:13 AM, Joril <jor...@gmail.com> wrote:

>
> On 26 Ott, 13:41, Mike Conley <mconl...@gmail.com> wrote:
> > > I see, but I need a proper shallow copy instead, with every
> > > attribute.. Is there no way? :/
> >
> > > What is missed?
> >
> > I am not sure what you mean by shallow copy. The fact that there are
> > relations to be lazy loaded is present in the new object when
> instantiated.
> > Obviously the objects pointed to by the relation are not copied, but I
> would
> > call that a deep copy, and to do that you would need to iterate over them
> > also.
>
> I'm sorry, by "shallow copy" I mean that only the parent object should
> be a copy (=different instance), while the related ones should be kept
> as-is...
>
> For example, given an object A that references B and C, a shallow copy
> of A would be made up of a copy of A that references the original B
> and C (not copies of B or C).
>
> So, in Python a non-automatic shallow copy would be:
>
> A = Some_class()
> A.refs = [B, C]
> Acopy = Some_class()
> Acopy.refs = A.refs
>
> My problem is that if A.refs has to be lazy loaded, when I try to copy
> it over to Acopy, it triggers the query, and I'd like to avoid that,
> while still copying the fact that Acopy.refs should be the same as
> A.refs.
>
> Thanks for your attention again!
>
>
So, let's understand the underlying data model.

We say, A is a parent object related to B and C children.
(1) If this is a one-to-many relationship, then B and C will contain foreign
keys pointing at A. Copying of A to Acopy cannot have references point at
[B, C] because the children cannot point at two parents at the same time;
there is only one foreign key column.
(2) If this is a many-to-many relationship, then there will be another table
between A and [B,C] managing the many-to-many connection and something needs
to be done during the copy to preserve the relationships.

Which do we have here?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to