-
Notifications
You must be signed in to change notification settings - Fork 32
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
Transactions #51
Comments
I've just accomplished it! instead of using $sale_item->sales_id = $sales->id; I've used $sale_item->sales_id = $sales; May I just say it is very simple and elegant solution you guys have there? Perhaps it could go on the documentation? Each day I'm loving Respect\Relational more! :) |
Hello @jonathanhayama you can do yourself ;) |
I have a similar problem, but I believe it is a bit more complex than that. Households need to save objects that have different identifier (ID only and different from, or "table name" + id .. etc, etc) they have specific identifiers of an internal standard. something like: tb_people, identifier: ppl_id or something. From what I can find out is not possible "to set" An identifier for each object to be persisted ... Can anyone give a suggestion? |
@cristopher-rodrigues the base component for Relational, Respect\Data, implements the concept of styles: naming conventions that describe how the database is structured. It is a mixture of configuration and convention (you can choose which convention to follow). It is an unfinished feature (it works, but is split in two repositories) and since your problem seems to be related to naming conventions, I guess it could solve your problem: Here is the NorthWind style sample: https://github.com/Respect/Data/blob/master/library/Respect/Data/Styles/NorthWind.php. NorthWind is the sample database for the Microsoft SQL Server 2000, many people use that standard so we implemented it. Unfortunately, when I moved styles to Respect\Data I've been unable to move the tests as well, so the NorthWindTest is available here: https://github.com/Respect/Relational/blob/develop/tests/library/Respect/Relational/Styles/NorthWindTest.php These tests show how the naming conventions for these databases are different. The NorthWind class simply translates the identifiers (changing case and plurals), but you can make the methods more complex: <?php
class MyCustomStyle extends Standard
protected $pks = array('tb_people' => 'ppl_id', 'sales' => 'slid');
// Gets a primary key name
public function identifier($name)
{
return isset($this->pks[$name]) ? $this->pks[$name] : parent::identifier($name);
}
} Check out the tests for other styles to understand how each interface method works (identifier, remoteIdentifier, etc). |
@jonathanhayama would you like to write the docs section for that feature? =) There are some tests here for reference: |
Hi @alganet I would be really honored to write the docs for this section. I'll check the tests for reference as suggested. It may take a little while (I've recently got a few extra work to do), but I'll definitely do it! :) |
Hi @alganet So the problem of the styles we have already solved. The problem that I tried to report it is basically: |
Hi Again!
I was wondering how can I work with transactions like Rollback and Commit.
I've checked that the flush() method already deals with it, but here's what I'm trying to accomplish:
Let's say I have the following database structure:
I want to save a sale in one click. So here's what I'm trying to do:
The problem is that $sales->id is NULL as the mapper wasn't flushed at that point. I know I can flush it and get the ID I want, but if anything happens and I can't save the sale_item, the sale would be already commited, which means I'd have to delete it and flush the database again. Is it possible to achieve what I want?
The text was updated successfully, but these errors were encountered: