On Oct 26, 2011, at 12:10 PM, Jakob L. wrote:
> Hi!
>
> I added a new self-referential relationship to one of my tables but since I
> couldn't find how to create the new column through SA I added it to the db
> manually after checking how it's been done before.
>
> The code looks like this (using elixir):
> class User(Entity):
> username = Field(String(80), primary_key=True)
>
> # New fields
> parent = ManyToOne('User')
> children = OneToMany('User')
>
> So I added a field in the db with the name "parent_name" since I noticed
> thats how SA names foreign keys
OK you're getting confused here due to Elixir. SQLAlchemy doesn't ever name a
foreign key anything - that would be what Elixir is doing.
> and I also indexed it with the name ix_user_parent_name
>
> Do I need to do anything else to get this to work or have I done anything
> wrong?
Seems fine assuming that naming convention you're using is correct (I haven't
used Elixir much).
>
> What I get is: " 'str' object has no attribute '_state' " for that object in
> _get_committed_attr_by_column.
So this is something occurring on usage, not on the mapping, which is not shown
here. Somewhere a string value is being passed where an object should be,
such as if you were to say User().parent = "some string". I know that's not
explicitly what you're doing here but we can't know the issue without full code
and a stack trace.
> I read that this means that I add a string to a relationship object, but I
> could access the parents fields when testing.
It is likely more subtle where a string is being misinterpreted. The
offending line of code at least + full stack trace is the most important.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.