Comments (8)
It almost works in master, I added a pending spec for now. The issue on the rom-sql side is fixed, now the real problem we have is that Sequel's dataset returns 0
when we insert a tuple with a composite PK. We gotta figure out how to make it return the actual PK value in order to be able to return inserted tuples. In postgres we have RETURNING
support so it works there.
from rom-sql.
@solnic it has nothing to do with sequel. MySQL does not support returning. The only way to get info about inserted record AFAIK is to call LAST_INSERT_ID
function wich returns last fetched sequence (called AUTO_INCREMENT in MySQL) value. http://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id
When you create a composite PK for a table that implements many-to-many relation you don't use sequences at all, both columns of the PK are actually FKs. This is why LAST_INSERT_ID
returns 0, no sequences was touched, so let's return 0, why not?
Sequel can determine if a database supports RETURNING
clause or not, combining this with info if the PK is composite or not, we can decide (though cannot guarantee!) if we need to use values returned from Sequel or use values from the input tuple.
from rom-sql.
@flash-gordon right, and because of that we have a problem with mysql since we can't easily get back inserted tuple when there's no auto-incremental PK...maybe we should simply return the input tuples when we have a composite pk.
from rom-sql.
@solnic this is not the best we can do, a better option is to fetch inserted record based on provided tuples, ie reload them. Underlying dataset (table or DB view) could have triggers which could transform tuples as well (a common example is timestamp fields) and we do not want to return stale/incomplete data to the user.
Oh, also I want to admit that composite PKs are not a great idea after all because of this ^ kind of problems fwiw
from rom-sql.
@flash-gordon yeah immediately after posting my comment I realized that what you just said is what needs to be done :D
And yeah, I wouldn't recommend using composite pks for non-join tables.
Anyhow, commands are extendible and we already have pg-specific extensions. I guess we should add a mysql specific ext and do the tricks there.
I'm gonna mark this as "help-wanted" because I don't use mysql and my time is super limited and I really need to wrap up a lot of things for the release. This can be fixed later on if we don't manage to include it in 0.8.0.
from rom-sql.
Thanks for the attention on this matter.
In fact the records are persisted correctly, the problem is to map back the inserted records to Rom objects, as you already saw.
Since I'm just persisting these records as setup to my specs, I can deal with this error until a patch is released.
If I can help in anything, just let me know.
Thanks in advance!
from rom-sql.
If you're just seeding data for specs, then I'd recommend using Relation#insert
, this way your setup will be much simpler and faster. We're still discussing how to approach test data btw. Probably we'll introduce rom-fixtures at some point.
from rom-sql.
Thanks @solnic !
I'm getting familiar with rom-rb yet, so all my knowledge came from official documentation.
I'll use insert so.
Thanks again!
from rom-sql.
Related Issues (20)
- "SQLite3::SQLException: row value misused" because of nested parenthesis HOT 1
- Possible race condition when inferring schema HOT 6
- Legacy schema
- Multi_insert returns more results than expected in some specific conditions HOT 5
- Attribute methods not available *within* a relation, but are *outside* of a relation HOT 4
- create returns nil for custom primary keys HOT 4
- OVER clause lost from row_number functions. HOT 9
- Postgres Upsert command does not support specifying index predicate for partial unique indices
- Translate symbols in a hash applied to `Relation#where` to attributes HOT 1
- "undefined method `stream'" when trying to use the `:pg_streaming` plugin HOT 2
- Multi-Schema database HOT 1
- Relation#multi_insert fails with blob data HOT 4
- Add a custom `Create` command for sqlite
- Use of projection dsl is not available in Relation#exclude
- Support for ANY in condition DSL HOT 5
- Error when attempting to join relations across different databases HOT 3
- [Migration] schema_migrations and schema_info tables error HOT 2
- Support virtual columns in `union` queries
- Problem with :create command and custom types HOT 2
- `by_pk` causes stack overflow when used with single primary key while table define composite primary key
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rom-sql.