On Thu, 13 Nov 2008, Faheem Mitha wrote:

> On Wed, 12 Nov 2008, Michael Bayer wrote:
>
>> On Nov 12, 2008, at 3:31 PM, Faheem Mitha wrote:

>>> 4) A more general question:
>>> 
>>> I'm having difficulty parsing the last three lines in the itemized list in 
>>> Section "associationproxy".
>>> 
>>> "The relation is inspected ..." through "A creator funcion can be used..."
>>> 
>>> In particular, I'm having difficulty understanding the point of the 
>>> creator function in association_proxy. I see where creator functions are 
>>> defined (two places), but don't see them being used.
>> 
>> the association proxy manages an association relation across three objects, 
>> such as:
>> 
>> A->B->C
>> 
>> when you say something along the lines of:
>> 
>> A.someelement = C
>> 
>> the "B" is created implicitly by the association proxy.  The creator 
>> function is used to customize the process of creating the B instance.
>
> Hmm. Adding something like this would not be a bad idea, except with more 
> elaboration.
>
> Just to repeat, I didn't really follow the point of the last three bullet 
> points. No doubt I'm being obtuse, but I think a little explicitness would 
> not hurt here.
>
> * The relation is inspected to determind the type of the related objects.
>
> What relation are we talking about, and what types? What is the point of 
> determining the types? I guess in this case there are three objects and two 
> relations as described in your diagram above, namely
>
> A->B->C
>
> * To construct new instances, the type is called with the value being 
> assigned, or key and value for dicts.
>
> I have no idea what this means. Are the instances referred to instances of 
> the association object B as above?
>
> * A creator function can be used to create instances intead.
>
> I suppose we are talking about instances of B again.
>
> I'm looking at the simplest example that uses a creator function, namely the 
> User/Keyword example starting with
>
> def get_current_uid():
>
> Here the creator function is
>
> def _create_uk_by_keyword(keyword):
>    """A creator function."""
>    return UserKeyword(keyword=keyword)
>
> Now, can you point me a line in this example
>
> where there is the equivalent of
>
> A.someelement = C
>
> ? In this case it would be something like
>
> user.keywords = Keyword('foo')
>
> Hmm, I suppose
>
> for kw in (Keyword('its_big'), Keyword('its_heavy'), Keyword('its_wood')):
>    user.keywords.append(kw)
>
> is also creating association objects, since there is one association object 
> (here, UserKeyword) created for each new Keyword.
>
> In any case, I think it would be helpful to emphasize this point, since it is 
> not obvious, at least to me. Also, how does creator know where to get the 
> arguments from in general? Does it come via the "C" object (here Keywords)? 
> What happens if it isn't specified? Does it fall back to the constructor 
> instead, or something else?
>
> Incidentally, in the Broker/Stock example, the creator function, namely
>
> def _create_holding(stock, shares):
>    """A creator function, constructs Holdings from Stock and share 
> quantity."""
>    return Holding(stock=stock, shares=shares)
>
> isn't used anywhere that I can see, even implicitly, since no stocks are 
> added to holdings in the example.

On further consideration,

for stock in (Stock('JEK'), Stock('STPZ')):
     broker.holdings[stock] = 123

*is* actually creating Holding objects. Also, it is using stock and shares 
arguements, so I suppose

  def _create_holding(stock, shares):
     """A creator function, constructs Holdings from Stock and share 
quantity."""
     return Holding(stock=stock, shares=shares)

is coming into play somehow. However, I'm still unclear about the precise 
mechanism by which this works. Regardless, I think it would be helpful to 
flag these examples explicitly, as in "look, look, we're invoking the 
creator function and implicitly creating Holding objects here!" (or 
whatever).

                                                         Take care, Faheem.

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to