-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One to many relationships? #1
Comments
You should not map the relationship to a schematics type. Here is a working test case with your model: Let me know if this works for you! |
Thanks lkraider, and thanks again for contributing schemalchemy. I will try the tests. One reason I had defined the relationship using a schematics type was because I am loading the object in from json.loads through schematics like this |
Please take note I just updated the gist. I am using a serializable type to output the children when serializing the parent. My guess is that using a serializable setter would work for importing, I have not tested though. Edit: serializable setters are something not in this version of schematics, I have a branch with that feature here: https://github.com/nkey/schematics/tree/serializable-setter |
Thanks! To be honest, I am using schemalchemy with the latest versions of Schematics and SQLAlchemy and not the versions tagged in the repository. Now that I think of it, I should have mentioned that in my original post. I guess that feature was introduced after your initial work on schemalchemy. |
Right, it should work with the new versions, although I have not tested them. Let me know if you see something that look like incompatibilities. |
I merged serializable setters into my codebase, still working on getting it working. Manually adding children works and children are fetched from the database properly and placed into the list - this is a great improvement. However, json.loads still yields a "None" list of children - trying to figure that one out. |
The problem is that the import loop does not touch the serializable setters on init (it iterates Model._fields, while they are in Model._serializables). I got it to work by modifying the loop in schematics like so: - for field_name, field in self._fields.iteritems():
+ for field_name, field in itertools.chain(
+ self._fields.iteritems(),
+ ((s[0], s[1].type) for s in self._serializables.iteritems())
+ ): To be fair I tested in my own schematics branch, so I am not sure how it applies to the version you are running. Hopefully it helps. |
Finally, what I'm seeing is that my child object is in the _data dictonary, but with no reference to it in the parent._child (the SQLAlchemy attribute in the parent object - which is None / empty.) Also, it appears that parent._dict['child'][x]._value and parent._dict['child'][x]._type (the underscore attributes) are not set properly, but .value and .type are, so if I correct that, and then manually set parent._child = parent._data['child'], all is good. Edit I'll write a test case this weekend showing this |
I hacked something together based on the https://github.com/schematics/schematics/tree/aa0405ebcd44ea71b63b384c48d2a9e8149a7202 development branch that forces the import loop to touch the serializable setter: Note: don't use this in any real code, it is completely unverified for correctness, it WILL BREAK your project and destroy all you hold dear without discernment, kittens and puppies alike. |
Is this still an open issue? |
I'll have to work on getting serializable setters into schematics for this issue to begin to be fixed. |
Hi, I still have this in my backlog to merge your patch. Modifications to transform.py mostly got it working and I suspect your patchset is a more complete fix. Thank you so much for helping. |
Progress? |
Still WIP. Can track this issue in schematics: schematics/schematics#446 |
Thanks Paul - I will check it out as soon as I have time and provide On Mon, Oct 24, 2016 at 9:14 AM, Paul Eipper [email protected]
|
@nochristrequired, I would be very interested in your take on the tradeoffs between the two (excluding the pain of getting schematics to work, that is)? |
Schematics changes are ready in schematics/schematics#466 |
Hi, I love Schematics and I love SQLAlchemy, so I decided to try schemalchemy vs having two entity classes. Works great for single table.
I'm running into an issue with a one-to-many relationship though. If the record doesn't exist in both tables, it works fine. If there's an existing record, it seems to fail. I was wondering if you had experienced this in the past or may have any insight into how to fix the issue.
Here's my entity classes-
Here's the stack trace (database_shared.py is my code, doing a merge operation on the parent entity class, id like to do setter injection somehow and have the operations on the entity class itself... not sure if that's possible)
Any help would be greatly appreciated! Thanks for contributing this library. ;)
The text was updated successfully, but these errors were encountered: